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.github.reinert.jjschema.v1.CustomSchemaWrapper.java

protected void processAttributes(ObjectNode node, Class<?> type) {
    final Attributes attributes = type.getAnnotation(Attributes.class);
    if (attributes != null) {
        //node.put("$schema", SchemaVersion.DRAFTV4.getLocation().toString());
        if (!attributes.id().isEmpty()) {
            node.put("id", attributes.id());
        }//  ww w .java  2s  .com
        if (!attributes.description().isEmpty()) {
            node.put("description", attributes.description());
        }
        if (!attributes.pattern().isEmpty()) {
            node.put("pattern", attributes.pattern());
        }
        if (!attributes.title().isEmpty()) {
            node.put("title", attributes.title());
        }
        if (attributes.maximum() > -1) {
            node.put("maximum", attributes.maximum());
        }
        if (attributes.exclusiveMaximum()) {
            node.put("exclusiveMaximum", true);
        }
        if (attributes.minimum() > -1) {
            node.put("minimum", attributes.minimum());
        }
        if (attributes.exclusiveMinimum()) {
            node.put("exclusiveMinimum", true);
        }
        if (attributes.enums().length > 0) {
            ArrayNode enumArray = node.putArray("enum");
            String[] enums = attributes.enums();
            for (String v : enums) {
                enumArray.add(v);
            }
        }
        if (attributes.uniqueItems()) {
            node.put("uniqueItems", true);
        }
        if (attributes.minItems() > 0) {
            node.put("minItems", attributes.minItems());
        }
        if (attributes.maxItems() > -1) {
            node.put("maxItems", attributes.maxItems());
        }
        if (attributes.multipleOf() > 0) {
            node.put("multipleOf", attributes.multipleOf());
        }
        if (attributes.minLength() > 0) {
            node.put("minLength", attributes.minItems());
        }
        if (attributes.maxLength() > -1) {
            node.put("maxLength", attributes.maxItems());
        }
        if (attributes.required()) {
            setRequired(true);
        }
        if (attributes.readonly()) {
            node.put("readonly", attributes.readonly());
        }
    }
}

From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.RESTActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    RESTConfig restConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", RESTConfig.class);

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());
    parserState.setCurrentConfiguration(configuration);
    try {/*from   w ww . ja  v a2s. c  o  m*/
        ObjectNode json = (ObjectNode) configuration.getJson();

        configuration.setType(ACTIVITY_URI.resolve("#Config"));

        ObjectNode request = json.objectNode();
        json.put("request", request);

        String method = restConfig.getHttpMethod().toUpperCase();
        request.put("httpMethod", method);
        request.put("absoluteURITemplate", restConfig.getUrlSignature());

        ArrayNode headers = json.arrayNode();
        request.put("headers", headers);

        if (restConfig.getAcceptsHeaderValue() != null && !restConfig.getAcceptsHeaderValue().isEmpty()) {
            ObjectNode accept = json.objectNode();
            headers.add(accept);
            accept.put("header", "Accept");
            accept.put("value", restConfig.getAcceptsHeaderValue());
        }
        if (hasContent(method)) {
            if (restConfig.getContentTypeForUpdates() != null
                    && !restConfig.getContentTypeForUpdates().isEmpty()) {
                ObjectNode accept = json.objectNode();
                headers.add(accept);
                accept.put("header", "Content-Type");
                accept.put("value", restConfig.getContentTypeForUpdates());
            }
            if (restConfig.isSendHTTPExpectRequestHeader()) {
                ObjectNode accept = json.objectNode();
                headers.add(accept);
                accept.put("header", "Expect");
                accept.put("value", "100-Continue");
            }
        }
        if (restConfig.getOtherHTTPHeaders() != null && restConfig.getOtherHTTPHeaders().getList() != null)
            for (HTTPHeaders.List list : restConfig.getOtherHTTPHeaders().getList()) {
                String fieldName = list.getContent().get(0).getValue();
                String fieldValue = list.getContent().get(1).getValue();

                ObjectNode accept = json.objectNode();
                headers.add(accept);
                accept.put("header", fieldName);
                accept.put("value", fieldValue);
            }
        if (restConfig.getShowActualUrlPort() != null)
            json.put("showActualURLPort", restConfig.getShowActualUrlPort().booleanValue());
        if (restConfig.getShowResponseHeadersPort() != null)
            json.put("showResponseHeadersPort", restConfig.getShowResponseHeadersPort().booleanValue());

        if (restConfig.isShowRedirectionOutputPort())
            json.put("showRedirectionOutputPort", true);
        if (restConfig.getEscapeParameters() != null && !restConfig.getEscapeParameters())
            json.put("escapeParameters", false);
        if (restConfig.getOutgoingDataFormat() != null)
            json.put("outgoingDataFormat", restConfig.getOutgoingDataFormat());
        return configuration;
    } finally {
        parserState.setCurrentConfiguration(null);
    }
}

From source file:org.envirocar.server.rest.util.GeoJSON.java

@Override
public ObjectNode encode(MultiPoint geometry) throws GeometryConverterException {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = getJsonFactory().objectNode();
    json.put(TYPE_KEY, MULTI_POINT_TYPE);
    ArrayNode list = getJsonFactory().arrayNode();
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((Point) geometry.getGeometryN(i)));
    }// ww  w  .j  a  v  a 2  s . c  o m
    json.put(COORDINATES_KEY, list);
    return json;
}

From source file:org.envirocar.server.rest.util.GeoJSON.java

@Override
public ObjectNode encode(MultiLineString geometry) throws GeometryConverterException {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = getJsonFactory().objectNode();
    json.put(TYPE_KEY, MULTI_LINE_STRING_TYPE);
    ArrayNode list = getJsonFactory().arrayNode();
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((LineString) geometry.getGeometryN(i)));
    }//from  w w w. j  a v a 2 s . c  o m
    json.put(COORDINATES_KEY, list);
    return json;
}

From source file:org.envirocar.server.rest.util.GeoJSON.java

@Override
public ObjectNode encode(MultiPolygon geometry) throws GeometryConverterException {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = getJsonFactory().objectNode();
    json.put(TYPE_KEY, MULTI_POLYGON_TYPE);
    ArrayNode list = getJsonFactory().arrayNode();
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        list.add(encodeCoordinates((Polygon) geometry.getGeometryN(i)));
    }//from  w  ww  .ja  va  2 s . c  om
    json.put(COORDINATES_KEY, list);
    return json;
}

From source file:org.gitana.platform.client.changeset.ChangesetImpl.java

@Override
public void addTag(String tag) {
    ArrayNode array = null;

    if (!has(FIELD_TAGS)) {
        array = JsonUtil.createArray();// w w w.  j  a  va  2s .  c  om
        set(FIELD_TAGS, array);
    } else {
        array = getArray(FIELD_TAGS);
    }

    if (!JsonUtil.arrayContains(array, tag)) {
        array.add(tag);

        set(FIELD_TAGS, array);
    }
}

From source file:org.envirocar.server.rest.util.GeoJSON.java

@Override
public ObjectNode encode(GeometryCollection geometry) throws GeometryConverterException {
    Preconditions.checkNotNull(geometry);
    ObjectNode json = getJsonFactory().objectNode();
    json.put(TYPE_KEY, GEOMETRY_COLLECTION_TYPE);
    ArrayNode geometries = getJsonFactory().arrayNode();
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        geometries.add(encodeGeometry(geometry.getGeometryN(i)));
    }//from  w  w  w . j  a va2s.  co m
    json.put(GEOMETRIES_KEY, geometries);
    return json;
}

From source file:edu.nwpu.gemfire.monitor.service.ClusterWANInfoService.java

public ObjectNode execute(final HttpServletRequest request) throws Exception {

    // get cluster object
    Cluster cluster = Repository.get().getCluster();

    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();

    // members list
    ArrayNode connectedClusterListJson = mapper.createArrayNode();

    for (Map.Entry<String, Boolean> entry : cluster.getWanInformation().entrySet()) {
        ObjectNode clusterJSON = mapper.createObjectNode();
        clusterJSON.put("clusterId", entry.getKey());
        clusterJSON.put("name", entry.getKey());
        clusterJSON.put("status", entry.getValue());

        connectedClusterListJson.add(clusterJSON);
    }/*from w  w w  .j ava2  s.  com*/
    // Response JSON
    responseJSON.put("connectedClusters", connectedClusterListJson);
    // Send json response
    return responseJSON;
}

From source file:org.openepics.discs.ccdb.core.auditlog.AuditLogUtil.java

/**
 * Adds a map of key-value pairs under the key tag of the JSON
 *
 * @param key the key//  ww  w .jav  a 2  s.  co m
 * @param keyValuePairs map of pairs to be added
 * @return a reference to this instance of {@link AuditLogUtil}
 */
public AuditLogUtil addArrayOfMappedProperties(String key, Map<String, ?> keyValuePairs) {
    // Don't add anything if empty
    if (keyValuePairs.isEmpty()) {
        return this;
    }

    final ArrayNode arrayNode = MAPPER.createArrayNode();

    for (Entry<String, ?> entry : keyValuePairs.entrySet()) {
        final ObjectNode arrayObjectNode = MAPPER.createObjectNode();
        arrayObjectNode.put(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null);
        arrayNode.add(arrayObjectNode);
    }
    node.set(key, arrayNode);
    return this;
}

From source file:io.wcm.caravan.pipeline.extensions.hal.action.InlineEmbeddedCollection.java

private void moveEmbeddedCollection(HalResource halResource, String relation) {
    List<HalResource> embeddedResources = halResource.getEmbedded(relation);
    ObjectNode model = halResource.getModel();
    ArrayNode container = model.putArray(relation);
    // iterate on relation specific embedded resources
    embeddedResources.stream()/*from  w  ww. jav a  2 s .co m*/
            // get items
            .flatMap(e -> e.getEmbedded("item").stream())
            // get state
            .map(item -> item.removeEmbedded().removeLinks().getModel())
            // add to array
            .forEach(itemState -> container.add(itemState));
}