Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

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

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:managers.nodes.OutputStringManager.java

protected JsonNode toJSON(JsonNode properties) {
    ArrayNode tokens = JsonNodeFactory.instance.arrayNode();
    String content = properties.get("content").asText();
    String[] contentTokens = content.split(" ");
    for (String token : contentTokens) {
        tokens.add(token);/*from w  w w  . j a va2 s  .co  m*/
    }
    ((ObjectNode) properties).put("tokens", tokens);
    return properties;
}

From source file:com.nebhale.jsonpath.internal.component.WildcardPathComponent.java

@Override
protected JsonNode select(JsonNode input) {
    if (input.isArray()) {
        return input;
    } else {/*from w w  w .  j  a  v a  2s  . c o m*/
        ArrayNode result = JsonNodeFactory.instance.arrayNode();

        for (Iterator<JsonNode> i = input.elements(); i.hasNext();) {
            result.add(i.next());
        }

        return result;
    }
}

From source file:com.nebhale.jsonpath.internal.component.DeepWildcardPathComponent.java

private ArrayNode getAllNodes(JsonNode root) {
    ArrayNode nodes = JsonNodeFactory.instance.arrayNode();
    nodes.add(root);/*from  w  ww  .  j  a v  a 2  s.c om*/

    if (root.isArray()) {
        for (JsonNode node : root) {
            nodes.addAll(getAllNodes(node));
        }
    } else {
        for (Iterator<String> i = root.fieldNames(); i.hasNext();) {
            nodes.addAll(getAllNodes(root.get(i.next())));
        }
    }

    return nodes;
}

From source file:org.eel.kitchen.jsonschema.syntax.BasicSyntaxValidatorTest.java

@Test
public void syntaxCheckingCorrectlyBalksOnNonObject() {
    final JsonNode wrong = JsonNodeFactory.instance.nullNode();
    final KeywordBundle bundle = KeywordBundles.defaultBundle();
    final SyntaxValidator validator = new SyntaxValidator(bundle);

    final List<Message> messages = Lists.newArrayList();

    validator.validate(messages, wrong);

    assertEquals(messages.size(), 1);/*w  ww  . j av a 2 s. c o  m*/
    assertEquals(messages.get(0).getInfo("found").textValue(), NodeType.NULL.toString());
}

From source file:com.nebhale.jsonpath.internal.component.IndexPathComponentTest.java

@Test
public void selectMultiple() {
    ArrayNode expected = JsonNodeFactory.instance.arrayNode();
    expected.add(NODE_BOOK.get(0));//from w  w w.  j av a2s  .c o  m
    expected.add(NODE_BOOK.get(1));

    JsonNode result = new IndexPathComponent(null, "0, 1").select(NODE_BOOK);

    assertEquals(expected, result);
}

From source file:net.hamnaberg.json.Collection.java

public static Collection create(Optional<URI> href, List<Link> links, List<Item> items, List<Query> queries,
        Optional<Template> template, Optional<Error> error) {
    ObjectNode obj = JsonNodeFactory.instance.objectNode();
    obj.put("version", Version.ONE.getIdentifier());
    href.ifPresent(value -> obj.put("href", value.toString()));
    if (!links.isEmpty()) {
        obj.set("links", links.stream().map(Extended::asJson).collect(JsonNodeFactory.instance::arrayNode,
                ArrayNode::add, ArrayNode::addAll));
    }/*from ww w  .  ja v  a2s .  c  om*/
    if (!items.isEmpty()) {
        obj.set("items", items.stream().map(Extended::asJson).collect(JsonNodeFactory.instance::arrayNode,
                ArrayNode::add, ArrayNode::addAll));
    }
    if (!queries.isEmpty()) {
        obj.set("queries", queries.stream().map(Extended::asJson).collect(JsonNodeFactory.instance::arrayNode,
                ArrayNode::add, ArrayNode::addAll));
    }
    template.ifPresent(value -> obj.set("template", value.asJson()));
    error.ifPresent(value -> obj.set("error", value.asJson()));
    Collection coll = new Collection(obj);
    coll.validate();
    return coll;
}

From source file:io.confluent.connect.elasticsearch.Mapping.java

/**
 * Create an explicit mapping.//w w  w  .  j  a v  a2  s.  co  m
 * @param client The client to connect to Elasticsearch.
 * @param index The index to write to Elasticsearch.
 * @param type The type to create mapping for.
 * @param schema The schema used to infer mapping.
 * @throws IOException
 */
public static void createMapping(JestClient client, String index, String type, Schema schema)
        throws IOException {
    ObjectNode obj = JsonNodeFactory.instance.objectNode();
    obj.set(type, inferMapping(schema));
    PutMapping putMapping = new PutMapping.Builder(index, type, obj.toString()).build();
    JestResult result = client.execute(putMapping);
    if (!result.isSucceeded()) {
        throw new ConnectException("Cannot create mapping " + obj + " -- " + result.getErrorMessage());
    }
}

From source file:com.nebhale.jsonpath.internal.component.ChildPathComponentTest.java

@Test
public void selectMultiple() {
    JsonNode nodeStore = NODE.get("store");

    ArrayNode expected = JsonNodeFactory.instance.arrayNode();
    expected.add(nodeStore.get("book"));
    expected.add(nodeStore.get("bicycle"));

    JsonNode result = new ChildPathComponent(null, "book, bicycle").select(nodeStore);

    assertEquals(expected, result);//from   w w w  .  j  a  v  a  2 s  . c  o m
}

From source file:org.apache.solr.kelvin.ResponseAnalyzerLoader.java

@Override
protected void addDefaults() {
    if (this.resources.size() == 0) {
        //XmlResponseAnalyzer  xmlResponseAnalyzer = new XmlResponseAnalyzer();

        resources.add(new XmlResponseAnalyzer());
        resources.add(new XmlDoclistExtractorResponseAnalyzer());
        JsonNode emptyConfig = JsonNodeFactory.instance.objectNode();
        for (IConfigurable r : resources) {
            try {
                r.configure(emptyConfig);
            } catch (Exception e) {
                e.printStackTrace();/*from www  .j av a  2s. c o m*/
            }
        }
    }

}

From source file:com.nebhale.jsonpath.internal.component.ChildPathComponent.java

@Override
protected JsonNode select(JsonNode input) {
    if (input.isArray()) {
        ArrayNode result = JsonNodeFactory.instance.arrayNode();
        for (JsonNode node : input) {
            JsonNode nodeResult = selectNode(node);
            if (nodeResult != null) {
                if (nodeResult.isArray()) {
                    result.addAll((ArrayNode) nodeResult);
                } else {
                    result.add(nodeResult);
                }/* w  ww  .j av a  2  s. c  o m*/
            }
        }
        return result;
    } else {
        return selectNode(input);
    }
}