Example usage for com.fasterxml.jackson.databind.node ArrayNode add

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add

Introduction

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

Prototype

public ArrayNode add(JsonNode paramJsonNode) 

Source Link

Usage

From source file:com.googlecode.jsonschema2pojo.FragmentResolverTest.java

@Test
public void pathCanReferToArrayContentsByIndex() {

    ObjectNode root = new ObjectMapper().createObjectNode();

    ArrayNode a = root.arrayNode();
    root.put("a", a);

    a.add(root.objectNode());
    a.add(root.objectNode());//from  ww  w  . ja v  a  2s .c o m
    a.add(root.objectNode());

    assertThat(resolver.resolve(root, "#/a/0"), is(sameInstance(a.get(0))));
    assertThat(resolver.resolve(root, "#/a/1"), is(sameInstance(a.get(1))));
    assertThat(resolver.resolve(root, "#/a/2"), is(sameInstance(a.get(2))));

}

From source file:org.springframework.tuple.TupleToJsonStringConverter.java

private ArrayNode toArrayNode(List<?> source) {
    ArrayNode array = mapper.createArrayNode();
    for (Object value : source) {
        if (value != null) {
            array.add(toNode(value));
        }//from w  w  w . j  av  a 2  s  . c o  m
    }
    return array;
}

From source file:com.github.fge.avro.translators.RecordTranslator.java

@Override
protected void doTranslate(final Schema avroSchema, final MutableTree jsonSchema, final ProcessingReport report)
        throws ProcessingException {
    final List<Schema.Field> fields = avroSchema.getFields();

    if (fields.isEmpty()) {
        final ArrayNode node = FACTORY.arrayNode();
        node.add(FACTORY.objectNode());
        jsonSchema.getCurrentNode().put("enum", node);
        return;/*from  w ww  .j  av  a 2s.  co  m*/
    }

    final JsonPointer pwd = jsonSchema.getPointer();

    if (avroSchema.getDoc() != null)
        jsonSchema.getCurrentNode().put("description", avroSchema.getDoc());

    jsonSchema.setType(NodeType.OBJECT);

    final ArrayNode required = FACTORY.arrayNode();
    jsonSchema.getCurrentNode().put("required", required);

    jsonSchema.getCurrentNode().put("additionalProperties", false);

    final ObjectNode properties = FACTORY.objectNode();
    jsonSchema.getCurrentNode().put("properties", properties);

    String fieldName;
    Schema fieldSchema;
    Schema.Type fieldType;
    AvroTranslator translator;
    JsonPointer ptr;
    ObjectNode propertyNode;
    String s;

    /*
     * FIXME: "default" and readers'/writers' schema? Here, even with a
     * default value, the record field is marked as required.
     */
    for (final Schema.Field field : fields) {
        fieldName = field.name();
        fieldSchema = field.schema();
        fieldType = fieldSchema.getType();
        translator = AvroTranslators.getTranslator(fieldType);
        required.add(fieldName);
        ptr = JsonPointer.of("properties", fieldName);
        propertyNode = FACTORY.objectNode();
        properties.put(fieldName, propertyNode);
        injectDefault(propertyNode, field);
        jsonSchema.setPointer(pwd.append(ptr));
        translator.translate(fieldSchema, jsonSchema, report);
        jsonSchema.setPointer(pwd);
    }
}

From source file:org.activiti.rest.service.api.legacy.deployment.DeploymentArtifactsResource.java

@Get
public ObjectNode getDeploymentArtifacts() {
    if (authenticate() == false)
        return null;

    String deploymentId = (String) getRequest().getAttributes().get("deploymentId");

    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("No deployment id provided");
    }/*from  ww w . j  a v a 2s .  co  m*/

    Deployment deployment = ActivitiUtil.getRepositoryService().createDeploymentQuery()
            .deploymentId(deploymentId).singleResult();
    List<String> resourceList = ActivitiUtil.getRepositoryService().getDeploymentResourceNames(deploymentId);

    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    responseJSON.put("id", deployment.getId());
    responseJSON.put("name", deployment.getName());
    responseJSON.put("deploymentTime", RequestUtil.dateToString(deployment.getDeploymentTime()));
    responseJSON.put("category", deployment.getCategory());

    ArrayNode resourceArray = new ObjectMapper().createArrayNode();

    for (String resourceName : resourceList) {
        resourceArray.add(resourceName);
    }

    responseJSON.put("resources", resourceArray);

    return responseJSON;
}

From source file:org.fnl.rest.MaoRestResource.java

/**
 * Hello world.//from ww w  .  j  ava  2 s  .  c  om
 * Mao.
 *
 * REST API:
 * http://127.0.0.1:8181/onos/mao/hello
 *
 * @return Beijing
 */
@GET
@Path("hello")
public Response hello() {
    ObjectNode root = mapper().createObjectNode();
    root.put("Hello", 1080).put("Mao", 7181);

    ArrayNode array = root.putArray("RadioStation");
    array.add("192.168.1.1").add("127.0.0.1").add("10.3.8.211");

    return ok(root).build();
}

From source file:com.redhat.lightblue.rest.metadata.hystrix.GetEntityNamesCommand.java

@Override
protected String run() {
    LOGGER.debug("run:");
    Error.reset();/*  w w  w .  j  a  va 2  s.  c  o m*/
    Error.push(getClass().getSimpleName());
    try {
        HashSet<MetadataStatus> statusSet = new HashSet<>();
        for (String x : statuses) {
            statusSet.add(MetadataParser.statusFromString(x));
        }
        String[] names = getMetadata().getEntityNames(statusSet.toArray(new MetadataStatus[statusSet.size()]));
        ObjectNode node = NODE_FACTORY.objectNode();
        ArrayNode arr = NODE_FACTORY.arrayNode();
        node.put("entities", arr);
        for (String x : names) {
            arr.add(NODE_FACTORY.textNode(x));
        }
        return node.toString();
    } catch (Error e) {
        return e.toString();
    } catch (Exception e) {
        LOGGER.error("Failure: {}", e);
        return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString();
    }
}

From source file:com.collective.celos.UtilTest.java

@Test
public void getArrayPropertyWorks() {
    ObjectNode node = Util.newObjectNode();
    ArrayNode array = Util.newArrayNode();
    array.add("bar");
    node.put("foo", array);
    Assert.assertEquals(array, Util.getArrayProperty(node, "foo"));
}

From source file:com.nebhale.jsonpath.internal.parser.RecoveringPathParserTest.java

@Test
public void indexes() {
    JsonNode nodeBook = NODE.get("store").get("book");
    ArrayNode expected = JsonNodeFactory.instance.arrayNode();
    expected.add(nodeBook.get(0));
    expected.add(nodeBook.get(1));//from  w  w  w.ja v  a 2s.c  o m

    ParserResult result = this.parser.parse("$.store.book[0, 1]");

    assertNoProblems(result);
    assertEquals(expected, result.getPathComponent().get(NODE));
}

From source file:com.nebhale.jsonpath.internal.parser.RecoveringPathParserTest.java

@Test
public void wildcardDotChild() {
    JsonNode nodeStore = NODE.get("store");
    ArrayNode expected = JsonNodeFactory.instance.arrayNode();
    expected.add(nodeStore.get("book"));
    expected.add(nodeStore.get("bicycle"));

    ParserResult result = this.parser.parse("$.store.*");

    assertNoProblems(result);//from  www .j a  v  a  2  s. c om
    assertEquals(expected, result.getPathComponent().get(NODE));
}

From source file:com.nebhale.jsonpath.internal.parser.RecoveringPathParserTest.java

@Test
public void wildcardArrayChild() {
    JsonNode nodeStore = NODE.get("store");
    ArrayNode expected = JsonNodeFactory.instance.arrayNode();
    expected.add(nodeStore.get("book"));
    expected.add(nodeStore.get("bicycle"));

    ParserResult result = this.parser.parse("$.store[*]");

    assertNoProblems(result);//from ww  w  . j a  v  a  2s . co m
    assertEquals(expected, result.getPathComponent().get(NODE));
}