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.waarp.common.json.JsonHandlerTest.java

/**
 * Test method for {@link org.waarp.common.json.JsonHandler#createArrayNode()}.
 *///ww w .ja va2s  . c  om
@Test
public void testCreateArrayNode() {
    ArrayNode node = JsonHandler.createArrayNode();
    node.add(true);
    node.add("bytes".getBytes());
    node.add(2.0);
    node.add(3);
    node.add(5L);
    node.add("string");
    assertTrue(node.size() == 6);
    String result = JsonHandler.writeAsString(node);
    ArrayNode node2;
    try {
        node2 = (ArrayNode) JsonHandler.mapper.readTree(result);
    } catch (JsonProcessingException e) {
        fail(e.getMessage());
        return;
    } catch (IOException e) {
        fail(e.getMessage());
        return;
    }
    assertTrue(result.equals(JsonHandler.writeAsString(node2)));
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSfTaskTest.java

private ObjectNode buildServiceFunctionObjectNode1() {
    ObjectNode topNode = mapper.createObjectNode();

    ObjectNode sfNode = mapper.createObjectNode();
    sfNode.put(SfExporterFactory._NAME, SF_NAME.getValue());

    ArrayNode arrayNode = mapper.createArrayNode();
    arrayNode.add(sfNode);

    topNode.put(SfExporterFactory._SERVICE_FUNCTION, arrayNode);
    return topNode;
}

From source file:com.vaporwarecorp.mirror.feature.splash.SplashManagerImpl.java

@Override
public String getJsonValues() {
    final ArrayNode formItems = createArrayNode();
    for (String url : mUrls) {
        formItems.add(createTextNode("url", url));
    }//from   ww  w.j  av a  2  s.co  m
    return createJsonNode("formItems", formItems).toString();
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSffTaskTest.java

private ObjectNode buildServiceFunctionForwarderTopNode() {
    ObjectNode topNode = mapper.createObjectNode();
    ObjectNode sffNode = mapper.createObjectNode();
    ArrayNode sffArrayNode = mapper.createArrayNode();
    sffArrayNode.add(sffNode);

    topNode.put(SffExporterFactory._SERVICE_FUNCTION_FORWARDER, sffArrayNode);
    return topNode;
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSfTaskTest.java

private ObjectNode buildServiceFunctionObjectNode() {
    ObjectNode topNode = mapper.createObjectNode();

    ObjectNode sfNode = mapper.createObjectNode();
    sfNode.put(SfExporterFactory._NAME, SF_NAME.getValue());
    sfNode.put(SfExporterFactory._REST_URI, REST_URI);

    ArrayNode arrayNode = mapper.createArrayNode();
    arrayNode.add(sfNode);

    topNode.put(SfExporterFactory._SERVICE_FUNCTION, arrayNode);
    return topNode;
}

From source file:yadarts.server.json.GameFinishedEntityEncoder.java

private JsonNode encodeWinners(List<String> winners) {
    ArrayNode result = new ArrayNode(createJSONNodeFactory());

    for (String w : winners) {
        result.add(w);
    }/* w  w w  . j av a 2  s . c o  m*/

    return result;
}

From source file:org.jboss.aerogear.unifiedpush.rest.util.RequestTransformer.java

private JsonNode transformJson(JsonNode patch, StringBuilder json) throws IOException, JsonPatchException {
    JsonNode jsonNode = convertToJsonNode(json);
    for (JsonNode operation : patch) {
        try {/*  w  ww  .j av a 2  s .  c  o m*/
            final ArrayNode nodes = JsonNodeFactory.instance.arrayNode();
            nodes.add(operation);
            JsonPatch patchOperation = JsonPatch.fromJson(nodes);
            jsonNode = patchOperation.apply(jsonNode);
        } catch (JsonPatchException e) {
            logger.log(Level.FINEST, "ignore field not found");
        }
    }
    return jsonNode;
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSffTaskTest.java

private ObjectNode buildServiceFunctionForwarderObjectNode1() {
    ObjectNode topNode = mapper.createObjectNode();

    ObjectNode sffNode = mapper.createObjectNode();
    sffNode.put(SffExporterFactory._NAME, SFF_NAME.getValue());

    ArrayNode sffArrayNode = mapper.createArrayNode();
    sffArrayNode.add(sffNode);

    topNode.put(SffExporterFactory._SERVICE_FUNCTION_FORWARDER, sffArrayNode);
    return topNode;
}

From source file:org.opendaylight.sfc.sbrest.provider.task.SbRestSffTaskTest.java

private ObjectNode buildServiceFunctionForwarderObjectNode() {
    ObjectNode topNode = mapper.createObjectNode();

    ObjectNode sffNode = mapper.createObjectNode();
    sffNode.put(SffExporterFactory._NAME, SFF_NAME.getValue());
    sffNode.put(SffExporterFactory._REST_URI, REST_URI);

    ArrayNode sffArrayNode = mapper.createArrayNode();
    sffArrayNode.add(sffNode);

    topNode.put(SffExporterFactory._SERVICE_FUNCTION_FORWARDER, sffArrayNode);
    return topNode;
}

From source file:org.wisdom.wamp.WampControllerPrefixTest.java

@Test
public void testPrefix() {
    message = null;/*  www .j a  v a  2 s  .  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("id", prefix);

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