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.opendaylight.sfc.sbrest.provider.task.SbRestSfgTaskTest.java

private ObjectNode buildServiceFunctionGroupObjectNode() {
    ObjectNode topNode = mapper.createObjectNode();
    ObjectNode sfgNode = mapper.createObjectNode();
    sfgNode.put(SfgExporterFactory._NAME, SFG_NAME);
    sfgNode.put(SfgExporterFactory._REST_URI, REST_URI);
    ArrayNode arrayNode = mapper.createArrayNode();

    arrayNode.add(sfgNode);
    topNode.put(SfgExporterFactory._SERVICE_FUNCTION_GROUP, arrayNode);
    return topNode;
}

From source file:com.github.reinert.jjschema.v1.SchemaWrapper.java

protected void processNullable() {
    final Nullable nullable = type.getAnnotation(Nullable.class);
    if (nullable != null) {
        String oldType = node.get("type").asText();
        ArrayNode typeArray = node.putArray("type");
        typeArray.add(oldType);
        typeArray.add("null");
    }//w  w  w . ja v  a2 s .  co m
}

From source file:com.marklogic.samplestack.web.security.SamplestackAuthenticationSuccessHandler.java

@Override
/**//from  w  ww .j  av a2 s. c  o  m
 * Override handler that sends 200 OK to client along with JSON
 * for the logged-in user.
 */
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    String targetUrlParam = getTargetUrlParameter();
    if (savedRequest != null && isAlwaysUseDefaultTargetUrl()
            || (targetUrlParam != null && StringUtils.hasText(request.getParameter(targetUrlParam)))) {
        requestCache.removeRequest(request, response);
    }

    clearAuthenticationAttributes(request);
    HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);
    Writer writer = responseWrapper.getWriter();
    String userName = ClientRole.securityContextUserName();

    ObjectNode userNode;

    Contributor contributor = contributorService.getByUserName(userName);
    if (contributor != null) {
        userNode = mapper.convertValue(contributor, ObjectNode.class);
    } else {
        userNode = mapper.createObjectNode();
        userNode.put("userName", userName);
    }
    ArrayNode roleNode = userNode.putArray("role");
    roleNode.add(ClientRole.securityContextRole().toString());

    mapper.writeValue(writer, userNode);
    writer.close();
}

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

@Override
public String exportJsonNameOnly(DataObject dataObject) {

    String ret = null;//from  w w  w .jav a  2  s.c  o  m
    if (dataObject instanceof ServiceFunctionGroup) {
        ServiceFunctionGroup obj = (ServiceFunctionGroup) dataObject;

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

    return ret;
}

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

@Override
protected JsonNode select(JsonNode input) {
    if (this.indexes.length == 1) {
        return input.get(this.indexes[0]);
    } else {/* w  w w .jav a 2 s  . c o m*/
        ArrayNode result = JsonNodeFactory.instance.arrayNode();
        for (int index : this.indexes) {
            result.add(input.get(index));
        }
        return result;
    }
}

From source file:org.envirocar.server.rest.encoding.json.TermsOfUseJSONEncoder.java

@Override
public ObjectNode encodeJSON(TermsOfUse t, AccessRights rights, MediaType mediaType) {
    ObjectNode root = getJsonFactory().objectNode();
    ArrayNode termsOfUse = root.putArray(JSONConstants.TERMS_OF_USE_KEY);

    for (TermsOfUseInstance u : t) {
        termsOfUse.add(termsOfUseEncoder.encodeJSON(u, rights, mediaType));
    }//from   ww  w .j a  v a  2  s.  co m
    return root;
}

From source file:org.hostdiscovery.app.Hostdiscommand.java

private JsonNode json(Iterable<Host> hosts) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();

    hosts.forEach(host -> result.add(jsonForEntity(host, Host.class)));
    return result;
}

From source file:com.github.fge.jsonschema.core.report.ListProcessingReport.java

@Override
public JsonNode asJson() {
    final ArrayNode ret = FACTORY.arrayNode();
    for (final ProcessingMessage message : messages)
        ret.add(message.asJson());
    return ret;//from w  w w  . ja va 2 s.c  o m
}

From source file:org.waarp.common.json.AdaptativeJsonHandlerTest.java

/**
 * Test method for {@link org.waarp.common.json.AdaptativeJsonHandler#createArrayNode()}.
 *///w ww.j  a v a2  s. c  om
@Test
public void testCreateArrayNode() {
    ArrayNode node = handler.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 = handler.writeAsString(node);
    ArrayNode node2;
    try {
        node2 = (ArrayNode) handler.mapper.readTree(result);
    } catch (JsonProcessingException e) {
        fail(e.getMessage());
        return;
    } catch (IOException e) {
        fail(e.getMessage());
        return;
    }
    assertTrue(result.equals(handler.writeAsString(node2)));
}

From source file:com.axelor.web.MapRest.java

@Path("/geomap/turnover")
@GET// w ww.  j av a2  s.c o  m
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getGeoMapData() {

    Map<String, BigDecimal> data = new HashMap<String, BigDecimal>();
    List<? extends SaleOrder> orders = saleOrderRepo.all().filter("self.statusSelect=?", 3).fetch();
    JsonNodeFactory factory = JsonNodeFactory.instance;
    ObjectNode mainNode = factory.objectNode();
    ArrayNode arrayNode = factory.arrayNode();

    ArrayNode labelNode = factory.arrayNode();
    labelNode.add("Country");
    labelNode.add("Turnover");
    arrayNode.add(labelNode);

    for (SaleOrder so : orders) {

        Country country = so.getMainInvoicingAddress().getAddressL7Country();
        BigDecimal value = so.getExTaxTotal();

        if (country != null) {
            String key = country.getName();

            if (data.containsKey(key)) {
                BigDecimal oldValue = data.get(key);
                oldValue = oldValue.add(value);
                data.put(key, oldValue);
            } else {
                data.put(key, value);
            }
        }
    }

    Iterator<String> keys = data.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        ArrayNode dataNode = factory.arrayNode();
        dataNode.add(key);
        dataNode.add(data.get(key));
        arrayNode.add(dataNode);
    }

    mainNode.put("status", 0);
    mainNode.put("data", arrayNode);
    return mainNode;
}