Search in sources :

Example 1 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 2 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)

Example 3 with JsonNode

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

the class TargetsCommandIntegrationTest method testJsonOutputWithShowCellPath.

@Test
public void testJsonOutputWithShowCellPath() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--json", "--show-cell-path", "//:test");
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    // Parse the observed JSON.
    JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()));
    assertTrue(observed.isArray());
    JsonNode targetNode = observed.get(0);
    assertTrue(targetNode.isObject());
    JsonNode cellPath = targetNode.get("buck.cell_path");
    assertNotNull(cellPath);
    assertEquals(cellPath.asText(), MorePaths.pathWithPlatformSeparators(tmp.getRoot().toRealPath()));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project druid by druid-io.

the class JSONToLowerParser method parse.

@Override
public Map<String, Object> parse(String input) {
    try {
        Map<String, Object> map = new LinkedHashMap<>();
        JsonNode root = objectMapper.readTree(input);
        Iterator<String> keysIter = (fieldNames == null ? root.fieldNames() : fieldNames.iterator());
        while (keysIter.hasNext()) {
            String key = keysIter.next();
            if (exclude.contains(key.toLowerCase())) {
                continue;
            }
            JsonNode node = root.path(key);
            if (node.isArray()) {
                final List<Object> nodeValue = Lists.newArrayListWithExpectedSize(node.size());
                for (final JsonNode subnode : node) {
                    final Object subnodeValue = valueFunction.apply(subnode);
                    if (subnodeValue != null) {
                        nodeValue.add(subnodeValue);
                    }
                }
                // difference from JSONParser parse()
                map.put(key.toLowerCase(), nodeValue);
            } else {
                final Object nodeValue = valueFunction.apply(node);
                if (nodeValue != null) {
                    // difference from JSONParser parse()
                    map.put(key.toLowerCase(), nodeValue);
                }
            }
        }
        return map;
    } catch (Exception e) {
        throw new ParseException(e, "Unable to parse row [%s]", input);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with JsonNode

use of com.fasterxml.jackson.databind.JsonNode in project elasticsearch by elastic.

the class GeoIpCacheTests method testCachesAndEvictsResults.

public void testCachesAndEvictsResults() throws Exception {
    GeoIpCache cache = new GeoIpCache(1);
    final NodeCache.Loader loader = key -> new IntNode(key);
    JsonNode jsonNode1 = cache.get(1, loader);
    assertSame(jsonNode1, cache.get(1, loader));
    // evict old key by adding another value
    cache.get(2, loader);
    assertNotSame(jsonNode1, cache.get(1, loader));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) NodeCache(com.maxmind.db.NodeCache) IntNode(com.fasterxml.jackson.databind.node.IntNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ESTestCase(org.elasticsearch.test.ESTestCase) IntNode(com.fasterxml.jackson.databind.node.IntNode) NodeCache(com.maxmind.db.NodeCache) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)3216 Test (org.junit.Test)1073 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)670 IOException (java.io.IOException)424 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)401 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)295 ArrayList (java.util.ArrayList)234 HashMap (java.util.HashMap)203 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 Map (java.util.Map)159 Test (org.junit.jupiter.api.Test)131 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)126 KernelTest (com.twosigma.beakerx.KernelTest)114 InputStream (java.io.InputStream)97 List (java.util.List)85 HttpGet (org.apache.http.client.methods.HttpGet)71 ByteArrayInputStream (java.io.ByteArrayInputStream)66 JsonException (jmri.server.json.JsonException)66 Deployment (org.activiti.engine.test.Deployment)66 JsonNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode)57