Search in sources :

Example 21 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project knox by apache.

the class KnoxShellTableRowDeserializer method parseCallHistoryListJSONNode.

private List<KnoxShellTableCall> parseCallHistoryListJSONNode(TreeNode callHistoryNode) throws IOException {
    final List<KnoxShellTableCall> callHistoryList = new LinkedList<>();
    TreeNode callNode;
    Map<Object, Class<?>> params;
    String invokerClass, method;
    Boolean builderMethod;
    for (int i = 0; i < callHistoryNode.size(); i++) {
        callNode = callHistoryNode.get(i);
        invokerClass = trimJSONQuotes(callNode.get("invokerClass").toString());
        method = trimJSONQuotes(callNode.get("method").toString());
        builderMethod = Boolean.valueOf(trimJSONQuotes(callNode.get("builderMethod").toString()));
        params = fetchParameterMap(callNode.get("params"));
        callHistoryList.add(new KnoxShellTableCall(invokerClass, method, builderMethod, params));
    }
    return callHistoryList;
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) LinkedList(java.util.LinkedList)

Example 22 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project knox by apache.

the class KnoxShellTableRowDeserializer method parseJsonWithData.

private KnoxShellTable parseJsonWithData(final TreeNode jsonContent) {
    if (jsonContent.get("title").size() != 0) {
        table.title(trimJSONQuotes(jsonContent.get("title").toString()));
    }
    final TreeNode headers = jsonContent.get("headers");
    for (int i = 0; i < headers.size(); i++) {
        table.header(trimJSONQuotes(headers.get(i).toString()));
    }
    final TreeNode rows = jsonContent.get("rows");
    for (int i = 0; i < rows.size(); i++) {
        TreeNode row = rows.get(i);
        table.row();
        for (int j = 0; j < row.size(); j++) {
            table.value(trimJSONQuotes(row.get(j).toString()));
        }
    }
    return table;
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode)

Example 23 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project che by eclipse.

the class CommandDeserializer method toCommand.

private List<String> toCommand(ArrayNode arrayCommandNode, DeserializationContext ctxt) throws JsonMappingException {
    List<String> commands = new ArrayList<>();
    for (TreeNode treeNode : arrayCommandNode) {
        if (treeNode instanceof TextNode) {
            TextNode textNode = (TextNode) treeNode;
            commands.add(textNode.asText());
        } else {
            throw ctxt.mappingException("Array 'command' contains not string element.");
        }
    }
    return commands;
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) ArrayList(java.util.ArrayList) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 24 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project data-prep by Talend.

the class ActionDefinitionDeserializer method deserialize.

@Override
public ActionDefinition deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    final TreeNode treeNode = jp.readValueAsTree();
    final TreeNode nodeName = treeNode.get("name");
    if (nodeName instanceof TextNode) {
        final String name = ((TextNode) nodeName).asText();
        return Providers.get(ActionRegistry.class).get(name);
    } else {
        LOGGER.error("No action available for: {}.", treeNode);
        return null;
    }
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry)

Example 25 with TreeNode

use of com.fasterxml.jackson.core.TreeNode in project candlepin by candlepin.

the class SingleValueWrapDeserializer method deserialize.

@Override
public String deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    TreeNode node = parser.readValueAsTree();
    if (node.isObject()) {
        log.debug("Processing {} as a containing object node.", this.fieldName);
        TreeNode valueNode = node.path(this.fieldName);
        if (valueNode.isMissingNode()) {
            throw new CandlepinJsonProcessingException("The field " + this.fieldName + " is missing from: " + node.asToken(), parser.getCurrentLocation());
        }
        return parseValueNode(valueNode);
    } else if (node.isValueNode()) {
        log.debug("Processing {} as a value node.", this.fieldName);
        return parseValueNode(node);
    } else {
        // Uh oh.
        throw new CandlepinJsonProcessingException("Unexpected " + this.fieldName + " node type: " + node.asToken(), parser.getCurrentLocation());
    }
}
Also used : CandlepinJsonProcessingException(org.candlepin.common.exceptions.CandlepinJsonProcessingException) TreeNode(com.fasterxml.jackson.core.TreeNode)

Aggregations

TreeNode (com.fasterxml.jackson.core.TreeNode)34 TextNode (com.fasterxml.jackson.databind.node.TextNode)11 JsonParser (com.fasterxml.jackson.core.JsonParser)10 IOException (java.io.IOException)8 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 HashMap (java.util.HashMap)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)4 BsonParser (de.undercouch.bson4jackson.BsonParser)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)3 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Sets (com.google.common.collect.Sets)3 Iterator (java.util.Iterator)3 Test (org.junit.Test)3 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2