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.n52.io.geojson.GeoJSONEncoder.java

public ObjectNode encode(GeometryCollection geometry, int parentSrid) throws GeoJSONException {
    checkNotNull(geometry);/*w  w  w .  ja v a 2  s.  com*/
    ObjectNode json = jsonFactory.objectNode();
    ArrayNode geometries = json.put(TYPE, GEOMETRY_COLLECTION).putArray(GEOMETRIES);
    int srid = encodeCRS(json, geometry, parentSrid);
    for (int i = 0; i < geometry.getNumGeometries(); ++i) {
        geometries.add(encodeGeometry(geometry.getGeometryN(i), srid));
    }
    return json;
}

From source file:org.onosproject.EvacuateCommand.java

private ObjectNode json(ObjectMapper mapper, Device device, List<FlowEntry> flows) {
    ObjectNode result = mapper.createObjectNode();
    ArrayNode array = mapper.createArrayNode();

    flows.forEach(flow -> array.add(jsonForEntity(flow, FlowEntry.class)));

    result.put("device", device.id().toString()).put("flowCount", flows.size()).set("flows", array);
    return result;
}

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

@Override
protected JsonNode select(JsonNode input) {
    if (input.isArray()) {
        ArrayNode result = JsonNodeFactory.instance.arrayNode();
        for (JsonNode node : input) {
            JsonNode nodeResult = selectNode(node);
            if (nodeResult != null) {
                if (nodeResult.isArray()) {
                    result.addAll((ArrayNode) nodeResult);
                } else {
                    result.add(nodeResult);
                }/*  ww w .j a  va2s  .  com*/
            }
        }
        return result;
    } else {
        return selectNode(input);
    }
}

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

@Override
protected void processNullable() {
    final Nullable nullable = getAccessibleObject().getAnnotation(Nullable.class);
    if (nullable != null) {
        if (isEnumWrapper()) {
            ((ArrayNode) getNode().get("enum")).add("null");
        } else {/*from   w ww . ja v a2s .c  o m*/
            String oldType = getType();
            ArrayNode typeArray = getNode().putArray("type");
            typeArray.add(oldType);
            typeArray.add("null");
        }
    }
}

From source file:org.walkmod.conf.providers.yml.RemoveChainsYMLAction.java

@Override
public void doAction(JsonNode node) throws Exception {
    HashSet<String> chainsSet = new HashSet<String>(chains);
    ArrayNode chainsList = null;//from w w w .ja v  a2  s  .  co  m
    ObjectMapper mapper = provider.getObjectMapper();

    if (node.has("chains")) {
        JsonNode aux = node.get("chains");
        if (aux.isArray()) {
            chainsList = (ArrayNode) node.get("chains");
            Iterator<JsonNode> it = chainsList.iterator();
            ArrayNode newChainsList = new ArrayNode(mapper.getNodeFactory());
            while (it.hasNext()) {
                JsonNode next = it.next();
                if (next.isObject()) {
                    String type = next.get("name").asText();
                    if (!chainsSet.contains(type)) {
                        newChainsList.add(next);
                    }
                }
            }
            ObjectNode oNode = (ObjectNode) node;
            if (newChainsList.size() > 0) {
                oNode.set("chains", newChainsList);
            } else {
                oNode.remove("chains");
            }
            provider.write(node);
        }
    } else if (node.has("transformations") && chainsSet.contains("default")) {
        ObjectNode oNode = (ObjectNode) node;
        oNode.remove("transformations");
        provider.write(node);
    }

}

From source file:org.apache.drill.optiq.DrillJoinRel.java

private int rename(DrillImplementor implementor, int inputId, List<String> inputFields,
        List<String> outputFields) {
    final ObjectNode project = implementor.mapper.createObjectNode();
    project.put("op", "project");
    project.put("input", inputId);
    final ArrayNode transforms = implementor.mapper.createArrayNode();
    project.put("projections", transforms);
    for (Pair<String, String> pair : Pair.zip(inputFields, outputFields)) {
        final ObjectNode objectNode = implementor.mapper.createObjectNode();
        transforms.add(objectNode);
        objectNode.put("expr", pair.left);
        objectNode.put("ref", "output." + pair.right);
        //      objectNode.put("ref", pair.right);
    }//from w  ww  . j a  v a  2 s . co  m
    return implementor.add(project);
}

From source file:org.apache.streams.rss.serializer.SyndEntrySerializer.java

private void serializeListOfStrings(List toSerialize, String key, ObjectNode node, JsonNodeFactory factory) {
    if (toSerialize == null || toSerialize.size() == 0)
        return;//from  w  ww . j a va 2 s.c  om
    ArrayNode keyNode = factory.arrayNode();
    for (Object obj : toSerialize) {
        if (obj instanceof String) {
            keyNode.add((String) obj);
        } else {
            LOGGER.debug("Array at Key:{} was expecting item types of String. Received class : {}", key,
                    obj.getClass().toString());
        }
    }
    node.put(key, keyNode);
}

From source file:org.envirocar.server.rest.validation.JSONSchemaResourceFilterFactory.java

protected void validate(JsonNode instance, JsonSchema schema) throws ValidationException, ProcessingException {
    ProcessingReport report = schema.validate(instance);
    if (!report.isSuccess()) {
        ObjectNode error = factory.objectNode();
        ArrayNode errors = error.putArray(JSONConstants.ERRORS_KEY);
        for (ProcessingMessage message : report) {
            errors.add(message.asJson());
        }/*from  w  ww  . j  a v a2 s . c o  m*/
        error.put(JSONConstants.INSTANCE_KEY, instance);
        throw new JSONValidationException(error);
    }
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.SpreadsheetActivityParser.java

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

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());

    ObjectNode json = (ObjectNode) configuration.getJson();
    configuration.setType(ACTIVITY_URI.resolve("#Config"));

    ObjectNode columnRange = json.objectNode();
    json.put("columnRange", columnRange);
    makeRange(config.getColumnRange(), columnRange);

    ObjectNode rowRange = json.objectNode();
    json.put("rowRange", rowRange);
    makeRange(config.getRowRange(), rowRange);

    if (config.getEmptyCellValue() != null)
        json.put("emptyCellValue", config.getEmptyCellValue());

    ArrayNode columnNames = json.arrayNode();
    if (config.getColumnNames() != null && config.getColumnNames().getEntry() != null) {
        for (SpreadsheetColumnNameEntry entry : config.getColumnNames().getEntry()) {
            ObjectNode mapping = json.objectNode();
            columnNames.add(mapping);
            mapping.put("column", entry.getString().get(0));
            mapping.put("port", entry.getString().get(1));
        }/*from  ww w .  j av  a 2 s.c o m*/
        if (columnNames.size() > 0)
            json.put("columnNames", columnNames);
    }

    json.put("allRows", config.isAllRows());
    json.put("excludeFirstRow", config.isExcludeFirstRow());
    json.put("ignoreBlankRows", config.isIgnoreBlankRows());
    if (config.getEmptyCellPolicy() != null)
        json.put("emptyCellPolicy", config.getEmptyCellPolicy().value());
    if (config.getOutputFormat() != null)
        json.put("outputFormat", config.getOutputFormat().value());
    if (config.getCsvDelimiter() != null)
        json.put("csvDelimiter", config.getCsvDelimiter());

    return configuration;
}

From source file:org.dswarm.graph.gdm.test.GDMResource3Test.java

private ObjectNode getMABXMLContentSchema() {

    final ObjectNode requestJson = objectMapper.createObjectNode();
    requestJson.put("record_identifier_attribute_path",
            "http://www.ddb.de/professionell/mabxml/mabxml-1.xsd#id");
    final ArrayNode keyAttributePaths = objectMapper.createArrayNode();
    keyAttributePaths.add(
            "http://www.ddb.de/professionell/mabxml/mabxml-1.xsd#feld\u001Ehttp://www.ddb.de/professionell/mabxml/mabxml-1.xsd#nr");
    keyAttributePaths.add(/*from   w  w  w.j a  va 2  s . c o  m*/
            "http://www.ddb.de/professionell/mabxml/mabxml-1.xsd#feld\u001Ehttp://www.ddb.de/professionell/mabxml/mabxml-1.xsd#ind");
    requestJson.set("key_attribute_paths", keyAttributePaths);
    requestJson.put("value_attribute_path",
            "http://www.ddb.de/professionell/mabxml/mabxml-1.xsd#feld\u001Ehttp://www.w3.org/1999/02/22-rdf-syntax-ns#value");

    return requestJson;
}