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:org.wisdom.wamp.WampControllerPrefixTest.java

@Test
public void testPrefixFromUnknownClient() {
    message = null;//from  w  ww .  j  av a  2s . co  m
    Json json = new JsonService();
    Publisher publisher = mock(Publisher.class);
    final Answer<Object> answer = new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            message = (String) invocation.getArguments()[2];
            return null;
        }
    };
    doAnswer(answer).when(publisher).send(anyString(), anyString(), anyString());

    WampController controller = new WampController(json, publisher, TestConstants.PREFIX);
    controller.open("id");
    assertThat(message).isNotNull();

    ArrayNode prefix = json.newArray();
    prefix.add(MessageType.PREFIX.code());
    prefix.add("calc");
    prefix.add("http://example.com/simple/calc#");
    controller.onMessage("unknown", prefix);

    Map.Entry<String, WampClient> entry = controller.getClientById("id");
    assertThat(entry).isNotNull();
    assertThat(entry.getValue().getUri("calc:square")).isNotEqualTo("http://example.com/simple/calc#square");
    assertThat(entry.getValue().getUri("http://perdu.com")).isEqualTo("http://perdu.com");
}

From source file:gist.ac.netcs.fwdtraffic.rest.FwdTrafficRestComponent.java

@GET
@Produces(MediaType.APPLICATION_JSON)//from w w w. j a va2s  .com
public Response getAll() {
    service = get(FwdTrafficService.class);
    map = service.getMap();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.createObjectNode();
    ArrayNode dev = mapper.createArrayNode();
    ObjectNode element = mapper().createObjectNode();

    for (DeviceId devId : map.keySet()) {
        ArrayNode flow = mapper().createArrayNode();
        map.get(devId).forEach((k, v) -> flow.add(convert(k, v)));
        element.set(devId.toString(), flow);
    }

    // iterate the map, extract the element and fill up element JSON obj
    // hint: need to generate flow ArrayNode first, add converted
    // JSON object of host pair and counter into the flow
    // Add flow into element by specifying switch id

    dev.add(element);
    root.set("data", dev);
    return ok(root).build();
}

From source file:org.modeshape.web.jcr.rest.model.RestQueryPlanResult.java

@Override
public ObjectNode toJSON(Json json) {
    ObjectNode result = json.newObject();
    result.put("statement", statement);
    result.put("language", language);
    result.put("abstractQueryModel", aqm);
    String[] planParts = plan.split("\\n");
    ArrayNode planArray = result.putArray("queryPlan");
    for (String part : planParts) {
        planArray.add(part);
    }//  w w  w .  j  ava  2s.  c o m
    return result;
}

From source file:com.redhat.lightblue.query.NaryValueRelationalExpression.java

/**
 * Returns a json representation of this query
 *///www  .j a v a  2  s .co  m
@Override
public JsonNode toJson() {
    ArrayNode arr = getFactory().arrayNode();
    for (Value x : values) {
        arr.add(x.toJson());
    }
    return getFactory().objectNode().put("field", getField().toString()).put("op", getOp().toString())
            .set("values", arr);
}

From source file:org.opendaylight.sfc.sbrest.json.SfExporterFactory.java

@Override
public String exportJsonNameOnly(DataObject dataObject) {

    String ret = null;//from  w w  w . j  a  v  a2 s . c  o  m
    if (dataObject instanceof ServiceFunction) {
        ServiceFunction obj = (ServiceFunction) dataObject;

        ObjectNode node = mapper.createObjectNode();
        node.put(_NAME, obj.getName().getValue());
        ArrayNode sfArray = mapper.createArrayNode();
        sfArray.add(node);
        ret = "{\"" + _SERVICE_FUNCTION + "\":" + sfArray.toString() + "}";
    } else {
        throw new IllegalArgumentException("Argument is not an instance of ServiceFunction");
    }

    return ret;
}

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

private JsonNode selectNode(JsonNode input) {
    if (this.names.length == 1) {
        return input.get(this.names[0]);
    } else {/* w ww  .  j  a v a 2s. c  o m*/
        ArrayNode result = JsonNodeFactory.instance.arrayNode();
        for (String name : this.names) {
            result.add(input.get(name));
        }
        return result;
    }
}

From source file:org.opendaylight.sfc.sbrest.json.RspExporterFactory.java

@Override
public String exportJsonNameOnly(DataObject dataObject) {

    String ret = null;/*from w  w w  . j  av a 2s  . co m*/
    if (dataObject instanceof RenderedServicePath) {
        RenderedServicePath obj = (RenderedServicePath) dataObject;

        ObjectNode node = mapper.createObjectNode();
        node.put("name", obj.getName().getValue());
        ArrayNode rspArray = mapper.createArrayNode();
        rspArray.add(node);
        ret = "{\"" + _RENDERED_SERVICE_PATH + "\":" + rspArray.toString() + "}";
    } else {
        throw new IllegalArgumentException("Argument is not an instance of RenderedServicePath");
    }

    return ret;
}

From source file:com.redhat.lightblue.query.ArrayContainsExpression.java

/**
 * Returns a json representation of the query
 *//*w  ww.ja va2 s .  co m*/
@Override
public JsonNode toJson() {
    ArrayNode arr = getFactory().arrayNode();
    for (Value x : values) {
        arr.add(x.toJson());
    }
    return getFactory().objectNode().put("array", array.toString()).put("contains", op.toString()).set("values",
            arr);
}

From source file:com.rusticisoftware.tincan.Group.java

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectNode node = super.toJSONNode(version);
    if (this.getMembers() != null && this.getMembers().size() > 0) {
        ArrayNode memberNode = Mapper.getInstance().createArrayNode();
        for (Agent member : this.getMembers()) {
            memberNode.add(member.toJSONNode(version));
        }/*from www .j a v a2s . c  o m*/
        node.put("member", memberNode);
    }
    return node;
}

From source file:org.jolokia.client.request.J4pConnectionPoolingIntegrationTest.java

private String getJsonResponse(String message) {
    final ObjectMapper objectMapper = new ObjectMapper();
    final ObjectNode node = objectMapper.createObjectNode();

    final ArrayNode arrayNode = objectMapper.createArrayNode();
    arrayNode.add("java.lang:type=Memory");
    node.putArray("value").addAll(arrayNode);

    node.put("status", 200);
    node.put("timestamp", 1244839118);

    return node.toString();
}