Search in sources :

Example 11 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.

the class ANode method iterateObject.

/**
     * Iterate over a Jackson object and create a Java Map.
     *
     * @param node. ObjectNode. The Jackson node to set up as a Map.
     * @return Map. Returns the Map implementation of the Jackson node.
     */
Map iterateObject(ObjectNode node) {
    Map m = new HashMap();
    Iterator it = node.iterator();
    it = node.fieldNames();
    while (it.hasNext()) {
        String key = (String) it.next();
        Object s = node.get(key);
        if (s instanceof TextNode) {
            TextNode t = (TextNode) s;
            m.put(key, t.textValue());
        } else if (s instanceof DoubleNode) {
            DoubleNode t = (DoubleNode) s;
            m.put(key, t.numberValue());
        } else if (s instanceof IntNode) {
            IntNode t = (IntNode) s;
            m.put(key, t.numberValue());
        } else
            // indeterminate, need to traverse
            m.put(key, s);
    }
    return m;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) HashMap(java.util.HashMap) Iterator(java.util.Iterator) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project dropwizard by dropwizard.

the class DefaultLoggingFactoryTest method canParseNewLoggerFormat.

@Test
public void canParseNewLoggerFormat() throws Exception {
    final DefaultLoggingFactory config = factory.build(new File(Resources.getResource("yaml/logging_advanced.yml").toURI()));
    assertThat(config.getLoggers()).contains(MapEntry.entry("com.example.app", new TextNode("INFO")));
    final JsonNode newApp = config.getLoggers().get("com.example.newApp");
    assertThat(newApp).isNotNull();
    final LoggerConfiguration newAppConfiguration = objectMapper.treeToValue(newApp, LoggerConfiguration.class);
    assertThat(newAppConfiguration.getLevel()).isEqualTo(Level.DEBUG);
    assertThat(newAppConfiguration.getAppenders()).hasSize(1);
    final AppenderFactory<ILoggingEvent> appenderFactory = newAppConfiguration.getAppenders().get(0);
    assertThat(appenderFactory).isInstanceOf(FileAppenderFactory.class);
    final FileAppenderFactory<ILoggingEvent> fileAppenderFactory = (FileAppenderFactory<ILoggingEvent>) appenderFactory;
    assertThat(fileAppenderFactory.getCurrentLogFilename()).isEqualTo("${new_app}.log");
    assertThat(fileAppenderFactory.getArchivedLogFilenamePattern()).isEqualTo("${new_app}-%d.log.gz");
    assertThat(fileAppenderFactory.getArchivedFileCount()).isEqualTo(5);
    assertThat(fileAppenderFactory.getBufferSize().toKilobytes()).isEqualTo(256);
    final ImmutableList<FilterFactory<ILoggingEvent>> filterFactories = fileAppenderFactory.getFilterFactories();
    assertThat(filterFactories).hasSize(2);
    assertThat(filterFactories.get(0)).isExactlyInstanceOf(TestFilterFactory.class);
    assertThat(filterFactories.get(1)).isExactlyInstanceOf(SecondTestFilterFactory.class);
    final JsonNode legacyApp = config.getLoggers().get("com.example.legacyApp");
    assertThat(legacyApp).isNotNull();
    final LoggerConfiguration legacyAppConfiguration = objectMapper.treeToValue(legacyApp, LoggerConfiguration.class);
    assertThat(legacyAppConfiguration.getLevel()).isEqualTo(Level.DEBUG);
    // We should not create additional appenders, if they are not specified
    assertThat(legacyAppConfiguration.getAppenders()).isEmpty();
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File) FilterFactory(io.dropwizard.logging.filter.FilterFactory) Test(org.junit.Test)

Example 13 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode 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 14 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project jsonschema2pojo by joelittlejohn.

the class FormatRuleTest method applyGeneratesTypeFromFormatValue.

@Test
public void applyGeneratesTypeFromFormatValue() {
    TextNode formatNode = TextNode.valueOf(formatValue);
    JType result = rule.apply("fooBar", formatNode, new JCodeModel().ref(String.class), null);
    assertThat(result.fullName(), equalTo(expectedType.getName()));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 15 with TextNode

use of com.fasterxml.jackson.databind.node.TextNode in project jsonschema2pojo by joelittlejohn.

the class TitleRuleTest method applyAddsDescriptionToJavadoc.

@Test
public void applyAddsDescriptionToJavadoc() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    TextNode titleNode = mapper.createObjectNode().textNode("some title");
    JDocComment result = rule.apply("fooBar", titleNode, jclass, null);
    assertThat(result, sameInstance(jclass.javadoc()));
    assertThat(result.size(), is(1));
    assertThat((String) result.get(0), is("some title\n<p>\n"));
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JDocComment(com.sun.codemodel.JDocComment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)23 Test (org.junit.Test)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 IntNode (com.fasterxml.jackson.databind.node.IntNode)7 ArrayList (java.util.ArrayList)7 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)6 JCodeModel (com.sun.codemodel.JCodeModel)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)4 JType (com.sun.codemodel.JType)4 List (java.util.List)4 TreeNode (com.fasterxml.jackson.core.TreeNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 JDefinedClass (com.sun.codemodel.JDefinedClass)2 JDocComment (com.sun.codemodel.JDocComment)2 NavMap (com.xrtb.blocks.NavMap)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2