All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.masterthought.cucumber.json.deserializers.OutputDeserializer Maven / Gradle / Ivy

Go to download

Provides pretty html reports for Cucumber (Behaviour-Driven Development). It works by generating html from the cucumber json report formatter. So can be used anywhere a json report is generated. Current use is in the cucumber jenkins plugin and a maven mojo to generate the same report from mvn command line when running locally.

There is a newer version: 5.8.6
Show newest version
package net.masterthought.cucumber.json.deserializers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;

import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.json.Output;

/**
 * Deserialize output messages depends supporting single and bi-dimensional arrays (JVM and Ruby implementations).
 * 
 * @author Damian Szczepanik (damianszczepanik@github)
 */
public class OutputDeserializer extends CucumberJsonDeserializer {

    @Override
    public Output deserialize(JsonParser parser, Configuration configuration)
            throws IOException, JsonProcessingException {
        JsonNode rootNode = parser.getCodec().readTree(parser);
        List list = parseOutput(rootNode);

        return new Output(list.toArray(new String[list.size()]));
    }

    /**
     * Converts passed node to list of strings. It supports single node and an array working as recursive method.
     * 
     * @param node
     *            node that should be parsed
     * @return extracted strings
     */
    private List parseOutput(JsonNode node) {
        List list = new ArrayList<>();

        if (node.isArray()) {
            for (JsonNode innerNode : node) {
                list.addAll(parseOutput(innerNode));
            }
        } else {
            list.add(node.asText());
        }

        return list;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy