Example usage for com.fasterxml.jackson.databind JsonNode asText

List of usage examples for com.fasterxml.jackson.databind JsonNode asText

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode asText.

Prototype

public abstract String asText();

Source Link

Usage

From source file:com.redhat.lightblue.config.ControllerConfiguration.java

@Override
public void initializeFromJson(JsonNode node) {
    try {//from  w w w  . j  a  v  a 2  s  .  c o m
        if (node != null) {
            JsonNode x = node.get("backend");
            if (x != null) {
                backend = x.asText();
            }
            x = node.get("controllerFactory");
            if (x != null) {
                controllerFactory = (Class<ControllerFactory>) Class.forName(x.asText());
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:la.alsocan.jsonshapeshifter.transformations.AdvancedCollectionTransformationTest.java

@Test
public void embeddedCollectionBindingShouldWithStaticValues() throws IOException {

    Schema source = Schema.buildSchema(new ObjectMapper().readTree(DataSet.EMBEDDED_COLLECTION_SCHEMA));
    Schema target = Schema.buildSchema(new ObjectMapper().readTree(DataSet.EMBEDDED_COLLECTION_SCHEMA));
    Transformation t = new Transformation(source, target);

    Iterator<SchemaNode> it = t.toBind();
    t.bind(it.next(), new ArrayNodeBinding((SchemaArrayNode) source.at("/someArrayOfArray")));
    t.bind(it.next(), new ArrayNodeBinding((SchemaArrayNode) source.at("/someArrayOfArray/{i}")));
    t.bind(it.next(), new StringConstantBinding("someString"));

    JsonNode payload = new ObjectMapper().readTree(DataSet.EMBEDDED_COLLECTION_PAYLOAD);
    JsonNode result = t.apply(payload);/*from   w  w  w  . j a v a  2  s  .co  m*/

    for (JsonNode iNode : (ArrayNode) result.at("/someArrayOfArray")) {
        for (JsonNode jNode : iNode) {
            assertThat(jNode.asText(), is(equalTo("someString")));
        }
    }
}

From source file:org.inaetics.pubsub.impl.serialization.jackson.JacksonSerializer.java

@Override
public MultipartContainer deserialize(byte[] bytes) {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    try {/*from   ww  w  .j a v a  2  s .  c om*/
        String json = new String(bytes);

        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        MultipartContainer container = new MultipartContainer();
        JsonNode jsonNode = mapper.readTree(json);
        Iterator<JsonNode> classes = jsonNode.get("classes").elements();
        Iterator<JsonNode> objects = jsonNode.get("objects").elements();

        while (objects.hasNext() && classes.hasNext()) {
            JsonNode object = (JsonNode) objects.next();
            JsonNode clazz = (JsonNode) classes.next();

            final Class<?> cls = Class.forName(clazz.asText());
            Object obj = mapper.convertValue(object, cls);
            container.addObject(obj);
        }

        return container;
    } catch (IOException e) {
        logService.log(LogService.LOG_ERROR, "Exception during JSON deserialize", e);
    } catch (ClassNotFoundException e) {
        logService.log(LogService.LOG_ERROR, "Exception during JSON deserialize", e);
    } finally {
        Thread.currentThread().setContextClassLoader(loader);
    }
    return null;
}

From source file:com.reprezen.swagedit.assist.ext.MediaTypeContentAssistExt.java

private Proposal createProposal(TypeDefinition type, JsonNode mediaType) {
    if (type instanceof ArrayTypeDefinition) {
        return new Proposal("- " + mediaType.asText(), mediaType.asText(), "", "mimeType");
    }/*from www .j a v a2s .co m*/
    return new Proposal(mediaType.asText(), mediaType.asText(), "", "mimeType");
}

From source file:org.walkmod.conf.providers.yml.RemoveModulesYMLAction.java

@Override
public void doAction(JsonNode node) throws Exception {
    if (node.has("modules")) {
        JsonNode aux = node.get("modules");
        ObjectMapper mapper = provider.getObjectMapper();
        if (aux.isArray()) {
            ArrayNode modulesList = (ArrayNode) node.get("modules");
            Iterator<JsonNode> it = modulesList.iterator();
            ArrayNode newModulesList = new ArrayNode(mapper.getNodeFactory());
            while (it.hasNext()) {
                JsonNode next = it.next();
                if (next.isTextual()) {
                    String text = next.asText();
                    if (!modules.contains(text)) {
                        newModulesList.add(text);
                    }/*from ww  w .  j  a  v  a 2 s . c  om*/
                }
            }
            ObjectNode oNode = (ObjectNode) node;
            if (newModulesList.size() > 0) {
                oNode.set("modules", newModulesList);
            } else {
                oNode.remove("modules");
            }
            provider.write(node);
        }
    }
}

From source file:com.orasi.sandbox.TestJSONDataProvider.java

@Test(dataProvider = "dataDiningNode")
public void testDiningNode(JsonNode node) {
    JsonNode nlist = node.path("diningList");
    Iterator<String> i1 = new IteratorMap<JsonNode, String>(nlist.iterator()) {
        @Override/*  ww  w . j a  v  a  2s . co m*/
        public String apply(JsonNode o) {
            return o.asText();
        }
    };
    Iterator<String> i2 = new ArrayIterator(DINING_LIST);
    Assert.assertEquals(i1, i2);
    Assert.assertEquals(node.path("diningInfo").path("partySize").asInt(), 1);
}

From source file:com.orasi.sandbox.TestYAMLDataProvider.java

@Test(dataProvider = "dataDiningNodeYAML")
public void testDiningNodeYAML(JsonNode node) {
    JsonNode nlist = node.path("diningList");
    Iterator<String> i1 = new IteratorMap<JsonNode, String>(nlist.iterator()) {
        @Override/*from www.j  ava 2s . co m*/
        public String apply(JsonNode o) {
            return o.asText();
        }
    };
    Iterator<String> i2 = new ArrayIterator(DINING_LIST);
    Assert.assertEquals(i1, i2);
    Assert.assertEquals(node.path("diningInfo").path("partySize").asInt(), 1);
}

From source file:ai.serotonin.backup.Backup.java

private void createBackup(final File filename) throws Exception {
    LOG.info("Creating backup file " + filename);

    try (final FileOutputStream out = new FileOutputStream(filename);
            final ZipOutputStream zip = new ZipOutputStream(out)) {
        final JsonNode files = configRoot.get("files");
        for (final JsonNode filesNode : files) {
            final String prefix = filesNode.get("prefix").asText();
            final JsonNode paths = filesNode.get("paths");
            for (final JsonNode path : paths)
                addFile(zip, prefix, path.asText());
        }//from   w  w  w . j av a  2 s  .c  o m
    }

    LOG.info("Created backup file " + filename + ", " + FileUtils.byteCountToDisplaySize(filename.length()));
}

From source file:io.gravitee.definition.jackson.datatype.plugins.resource.deser.ResourceDeserializer.java

@Override
public Resource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    Resource resource = new Resource();

    final JsonNode nameNode = node.get("name");
    if (nameNode != null) {
        resource.setName(nameNode.asText());
    } else {/*from  w w  w.j a  va  2 s. c o  m*/
        throw ctxt.mappingException("[resource] Name is required");
    }

    final JsonNode typeNode = node.get("type");
    if (typeNode != null) {
        resource.setType(typeNode.asText());
    } else {
        throw ctxt.mappingException("[resource] Type is required");
    }

    final JsonNode configurationNode = node.get("configuration");
    if (configurationNode != null) {
        resource.setConfiguration(configurationNode.toString());
    } else {
        throw ctxt.mappingException("[resource] Configuration is required");
    }

    final JsonNode enabledNode = node.get("enabled");
    if (enabledNode != null) {
        resource.setEnabled(enabledNode.asBoolean(true));
    } else {
        resource.setEnabled(true);
    }

    return resource;
}

From source file:com.googlecode.jsonschema2pojo.rules.DescriptionRule.java

/**
 * Applies this schema rule to take the required code generation steps.
 * <p>//from   w w w .j a  v a 2  s .  c o m
 * When a description node is found and applied with this rule, the value of
 * the description is added as a class level JavaDoc comment.
 * 
 * @param nodeName
 *            the name of the object to which this description applies
 * @param node
 *            the "description" schema node
 * @param generatableType
 *            comment-able code generation construct, usually a java class,
 *            which should have this description applied
 * @return the JavaDoc comment created to contain the description
 */
@Override
public JDocComment apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) {
    JDocComment javadoc = generatableType.javadoc();

    javadoc.append(node.asText());

    return javadoc;
}