Example usage for com.fasterxml.jackson.databind.node ObjectNode get

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.arpnetworking.logback.StenoEncoderTest.java

private static void assertMatchesJsonSchema(final String json) {
    try {//from   w  w w  . ja v a 2  s .c  o m
        final ObjectNode rootNode = (ObjectNode) JsonLoader.fromString(json);
        final ObjectNode contextNode = (ObjectNode) rootNode.get("context");
        if (contextNode != null) {
            contextNode.remove("logger");
            contextNode.remove("MDC_KEY");
            contextNode.remove("CONTEXT_KEY1");
            contextNode.remove("CONTEXT_KEY2");
        }
        final ProcessingReport report = VALIDATOR.validate(STENO_SCHEMA, rootNode);
        Assert.assertTrue(report.toString(), report.isSuccess());
    } catch (final IOException | ProcessingException e) {
        Assert.fail("Failed with exception: " + e);
    }
}

From source file:com.squarespace.template.ReferenceScannerTest.java

@Test
public void testSectionNesting() throws CodeException {
    ObjectNode result = scan("{.section a}{.section b}{.section c}{d}{.end}{.end}{.end}");
    render(result);/*from  w w w .j a v a2 s  .  com*/

    ObjectNode vars = (ObjectNode) result.get("variables");
    assertTrue(vars.get("a").get("b").get("c").get("d").isNull());

    result = scan("{.section a}{.end}{.section a}{.end}");
    render(result);
    assertTrue(vars.get("a").isObject());
}

From source file:org.apache.taverna.scufl2.translator.t2flow.TestDispatchLayerParsing.java

@Test
public void looping() throws Exception {
    Processor looping = processors.getByName("looping");
    Configuration config = scufl2Tools.configurationFor(looping, profile);
    ObjectNode json = config.getJsonAsObjectNode();
    JsonNode loop = json.get(LOOP);
    //        System.out.println(loop);
    String activityName = loop.get("conditionActivity").asText();
    Activity activity = profile.getActivities().getByName(activityName);
    assertNotNull("Unknown activity " + activityName, activity);

    assertEquals(true, loop.get("runFirst").asBoolean());

    // The properties
    assertEquals("fred", loop.get("compareValue").asText());
    assertEquals("value", loop.get("comparePort").asText());
    assertEquals(0.5, loop.get("delay").asDouble(), 0.01);
    assertEquals(false, loop.get("isFeedBack").asBoolean());
}

From source file:io.swagger.test.processors.JacksonProcessorTest.java

@Test
public void testConvertYamlWithEncoding() throws Exception {
    final String input = "type: application\nsubtype: yaml\ncharset: UTF-8";
    final MediaType type = new MediaType("application", "yaml", StandardCharsets.UTF_8.name());

    final String string = (String) EntityProcessorFactory.readValue(type,
            new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), String.class);
    assertEquals(string, input);//  ww  w .j  a v  a2  s.  c  o  m

    final ObjectNode json = (ObjectNode) EntityProcessorFactory.readValue(type,
            new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), JsonNode.class);
    assertEquals(json.get("type").asText(), "application");
    assertEquals(json.get("subtype").asText(), "yaml");
    assertEquals(json.get("charset").asText(), "UTF-8");
}

From source file:com.meltmedia.jackson.crypto.EncryptWithObjectMapperTest.java

@Test
public void shouldEncryptWithSerializerAnnotation()
        throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
    SerAnnotatedWithEncrypted toEncrypt = new SerAnnotatedWithEncrypted().withValue("some value");

    ObjectNode encrypted = mapper.readValue(mapper.writeValueAsString(toEncrypt), ObjectNode.class);

    EncryptedJson result = mapper.convertValue(encrypted.get("value"), EncryptedJson.class);
    JsonNode roundTrip = service.decryptAs(result, "UTF-8", JsonNode.class);

    assertThat(roundTrip.asText(), equalTo("c29tZSB2YWx1ZQ=="));

}

From source file:org.apache.streams.converter.test.HoconConverterTest.java

/**
 * Tests derived object substitution conversion from String to ObjectNode
 *//*  ww  w.j a va  2  s.c o m*/
@Test
public void testHoconConverter2() {

    final String TEST_JSON_2 = "{\"race\":\"klingon\",\"gender\":\"male\",\"age\":18}";

    ObjectNode result2 = (ObjectNode) HoconConverterUtil.convert(TEST_JSON_2, ObjectNode.class, "test2.conf",
            "demographics");

    assertNotNull(result2);
    assertTrue(result2.get("race") != null);
    assertTrue(result2.get("age").asDouble() == 18);
    assertTrue(result2.get("gender").asText().equals("female"));
}

From source file:com.redhat.lightblue.metadata.rdbms.model.RDBMS.java

@Override
public String toString() {
    Extensions<JsonNode> x = new Extensions<>();
    x.addDefaultExtensions();//  w  w w  . j  a v  a 2  s  .  co m
    JsonNodeFactory factory = JsonNodeFactory.withExactBigDecimals(false);
    JSONMetadataParser p = new JSONMetadataParser(x, new DefaultTypes(), factory);
    ObjectNode root = factory.objectNode();
    convert(p, root);
    return JsonUtils.prettyPrint(root.get("rdbms"));
}

From source file:io.swagger.test.processors.JacksonProcessorTest.java

@Test
public void testConvertXMLContent() throws Exception {
    String input = "<user><id>1</id><name>fehguy</name></user>";

    EntityProcessorFactory.addProcessor(JacksonProcessor.class, MediaType.APPLICATION_XML_TYPE);

    InputStream is = new ByteArrayInputStream(input.getBytes());
    ObjectNode o = (ObjectNode) EntityProcessorFactory.readValue(MediaType.APPLICATION_XML_TYPE, is,
            JsonNode.class);
    assertEquals(o.getClass(), ObjectNode.class);
    assertEquals(o.get("name").asText(), "fehguy");
}

From source file:io.swagger.test.processors.JacksonProcessorTest.java

@Test
public void testConvertJsonContent() throws Exception {
    String input = "{\"name\":\"fehguy\"}";
    EntityProcessorFactory.addProcessor(JacksonProcessor.class, MediaType.APPLICATION_JSON_TYPE);

    InputStream is = new ByteArrayInputStream(input.getBytes());
    ObjectNode o = (ObjectNode) EntityProcessorFactory.readValue(MediaType.APPLICATION_JSON_TYPE, is,
            JsonNode.class);
    assertEquals(o.getClass(), ObjectNode.class);
    assertEquals(o.get("name").asText(), "fehguy");
}

From source file:org.forgerock.openig.migrate.action.InlineDeclarationsAction.java

@Override
protected ObjectNode doMigrate(final RouteModel route, final ObjectNode configuration) {

    ArrayNode heap = (ArrayNode) configuration.get("heap");

    // Creates references
    for (ObjectModel source : route.getObjects()) {
        for (String pointer : source.getType().getPatterns()) {

            PathVisitor visitor = new PathVisitor(Pattern.compile(pointer));
            new NodeTraversal().traverse(source.getConfig(), visitor);

            for (PathVisitor.Match match : visitor.getMatches()) {
                JsonNode pointed = match.getNode();

                if (pointed.isArray()) {
                    int i = 0;
                    for (JsonNode item : pointed) {
                        bindArrayReference(source, route.findObject(item.asText()), match.getPointer(), i++);
                    }//  w w w  . j av  a2s .c om
                } else if (pointed.isTextual()) {
                    bindReference(source, route.findObject(pointed.asText()), match.getPointer());
                }
            }
        }
    }

    // Inline references as much as possible, starting from the leafs
    // TODO Consider Moving all candidates at once, this is probably not useful to process them step by step
    List<ObjectModel> candidates = findCandidates(route);
    while (!candidates.isEmpty()) {

        for (ObjectModel candidate : candidates) {
            Reference ref = candidate.getReferencedBy().get(0);
            if (ref.isArrayRef()) {
                ArrayNode array = (ArrayNode) ref.getSource().getConfig().at(ref.getPointer());
                array.set(ref.getIndex(), ref.getTarget().getNode());
            } else {
                // We'll just replace in place the value
                ObjectNode parent = (ObjectNode) ref.getSource().getConfig().at(parentOf(ref.getPointer()));
                parent.replace(lastSegmentOf(ref.getPointer()), ref.getTarget().getNode());
            }
            ref.getSource().getReferencesTo().remove(ref);
            ref.getTarget().getReferencedBy().remove(ref);
            ref.getTarget().markInlined();
        }

        candidates = findCandidates(route);
    }

    // Remove inlined references, Java 8 style
    Iterator<ObjectModel> iterator = route.getObjects().stream().filter(inlined()).sorted(byReverseIndex())
            .iterator();
    while (iterator.hasNext()) {
        ObjectModel next = iterator.next();
        heap.remove(next.getIndex());
    }

    return configuration;
}