Search in sources :

Example 71 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project presto by prestodb.

the class JsonRowDecoder method decodeRow.

@Override
public boolean decodeRow(byte[] data, Map<String, String> dataMap, Set<FieldValueProvider> fieldValueProviders, List<DecoderColumnHandle> columnHandles, Map<DecoderColumnHandle, FieldDecoder<?>> fieldDecoders) {
    JsonNode tree;
    try {
        tree = objectMapper.readTree(data);
    } catch (Exception e) {
        return true;
    }
    for (DecoderColumnHandle columnHandle : columnHandles) {
        if (columnHandle.isInternal()) {
            continue;
        }
        @SuppressWarnings("unchecked") FieldDecoder<JsonNode> decoder = (FieldDecoder<JsonNode>) fieldDecoders.get(columnHandle);
        if (decoder != null) {
            JsonNode node = locateNode(tree, columnHandle);
            fieldValueProviders.add(decoder.decode(node, columnHandle));
        }
    }
    return false;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) FieldDecoder(com.facebook.presto.decoder.FieldDecoder)

Example 72 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project orientdb by orientechnologies.

the class OGraphSONUtility method edgeFromJson.

/**
   * Creates an edge from GraphSON using settings supplied in the constructor.
   */
public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException {
    final Map<String, Object> props = OGraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes);
    final Object edgeId = getTypedValueFromJsonNode(json.get(GraphSONTokens._ID));
    final JsonNode nodeLabel = json.get(GraphSONTokens._LABEL);
    // assigned an empty string edge label in cases where one does not exist. this gets around the requirement
    // that blueprints graphs have a non-null label while ensuring that GraphSON can stay flexible in parsing
    // partial bits from the JSON. Not sure if there is any gotchas developing out of this.
    final String label = nodeLabel == null ? EMPTY_STRING : nodeLabel.textValue();
    final Edge e = factory.createEdge(edgeId, out, in, label);
    for (Map.Entry<String, Object> entry : props.entrySet()) {
        // if (this.edgePropertyKeys == null || this.edgePropertyKeys.contains(entry.getKey())) {
        if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) {
            e.setProperty(entry.getKey(), entry.getValue());
        }
    }
    return e;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) Edge(com.tinkerpop.blueprints.Edge)

Example 73 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project orientdb by orientechnologies.

the class OGraphSONUtility method vertexFromJson.

/**
   * Creates a vertex from GraphSON using settings supplied in the constructor.
   */
public Vertex vertexFromJson(final InputStream json) throws IOException {
    final JsonParser jp = jsonFactory.createParser(json);
    final JsonNode node = jp.readValueAsTree();
    return this.vertexFromJson(node);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 74 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project jvm-serializers by eishay.

the class JacksonJsonTree method readMedia.

protected static Media readMedia(JsonNode node) {
    Media media = new Media();
    JsonNode bitrate = node.get("bitrate");
    if (bitrate != null && !bitrate.isNull()) {
        media.bitrate = bitrate.intValue();
        media.hasBitrate = true;
    }
    media.copyright = node.path("copyright").textValue();
    media.duration = node.path("duration").longValue();
    media.format = node.path("format").textValue();
    media.height = node.path("height").intValue();
    media.player = Media.Player.valueOf(node.get("player").textValue());
    ArrayNode personsArrayNode = (ArrayNode) node.get("persons");
    int size = personsArrayNode.size();
    List<String> persons = new ArrayList<String>(size);
    for (JsonNode person : personsArrayNode) {
        persons.add(person.textValue());
    }
    media.persons = persons;
    media.size = node.get("size").intValue();
    media.title = node.get("title").textValue();
    media.uri = node.get("uri").textValue();
    media.width = node.get("width").intValue();
    return media;
}
Also used : Media(data.media.Media) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 75 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project buck by facebook.

the class AndroidLibraryAsAnnotationProcessorHostIntegrationTest method getOutputFile.

private Path getOutputFile(String targetName) {
    try {
        ProjectWorkspace.ProcessResult buildResult = workspace.runBuckCommand("targets", targetName, "--show-full-output", "--json");
        buildResult.assertSuccess();
        JsonNode jsonNode = objectMapper.reader().readTree(buildResult.getStdout()).get(0);
        assert jsonNode.has("buck.outputPath");
        return Paths.get(jsonNode.get("buck.outputPath").asText());
    } catch (Exception e) {
        fail(e.getMessage());
        return Paths.get("");
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1055 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)275 Test (org.junit.Test)267 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)165 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)125 IOException (java.io.IOException)124 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)97 HashMap (java.util.HashMap)78 ArrayList (java.util.ArrayList)75 HttpGet (org.apache.http.client.methods.HttpGet)69 JsonException (jmri.server.json.JsonException)66 Deployment (org.activiti.engine.test.Deployment)66 InputStream (java.io.InputStream)64 StringEntity (org.apache.http.entity.StringEntity)54 ByteArrayInputStream (java.io.ByteArrayInputStream)53 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)49 Map (java.util.Map)45 Task (org.activiti.engine.task.Task)41 HttpPost (org.apache.http.client.methods.HttpPost)39 Tree (org.apache.jackrabbit.oak.api.Tree)30