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.flipkart.zjsonpatch.ApplyProcessor.java

private void addToArray(List<String> path, JsonNode value, JsonNode parentNode) {
    final ArrayNode target = (ArrayNode) parentNode;
    String idxStr = path.get(path.size() - 1);

    if ("-".equals(idxStr)) {
        // see http://tools.ietf.org/html/rfc6902#section-4.1
        target.add(value);
    } else {/*from  w w  w.j a  v a2s. c om*/
        int idx = arrayIndex(idxStr.replaceAll("\"", ""), target.size());
        target.insert(idx, value);
    }
}

From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java

String getKeyStrokesJSON() {
    ObjectNode keyStrokesNode = JsonNodeFactory.instance.objectNode();

    for (Entry<String, KeyStroke> entry : getKeyStrokeMap().entrySet()) {
        if (entry.getValue() != null) {
            ArrayNode arrayNode = keyStrokesNode.putArray(entry.getKey());
            arrayNode.add(entry.getValue().getKeyCode());
            arrayNode.add(entry.getValue().getModifiers());
        } else {/*from   w ww  .  j  a  va  2s  .  c  o  m*/
            keyStrokesNode.putNull(entry.getKey());
        }
    }

    return keyStrokesNode.toString();
}

From source file:net.sf.jasperreports.jsonql.JsonQLExpressionsTest.java

private ArrayNode toArrayNode(JsonNodeContainer container) {
    ArrayNode result = jsonQLExecuter.getEvaluator().getEvaluationContext().getObjectMapper().createArrayNode();

    for (JRJsonNode node : container.getContainerNodes()) {
        result.add(node.getDataNode());
    }//from  ww  w  . j a  v  a 2 s  .c  o  m

    return result;
}

From source file:org.activiti.rest.service.api.runtime.ProcessInstanceQueryResourceTest.java

/**
 * Test querying process instance based on variables. POST query/process-instances
 *///from   w w  w .  ja  v a  2s.c o m
@Deployment
public void testQueryProcessInstancesWithVariables() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_QUERY);

    // Process variables
    ObjectNode requestNode = objectMapper.createObjectNode();
    ArrayNode variableArray = objectMapper.createArrayNode();
    ObjectNode variableNode = objectMapper.createObjectNode();
    variableArray.add(variableNode);
    requestNode.put("variables", variableArray);

    // String equals
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Integer equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67890);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Boolean equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", false);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String not equals
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "ghijkl");
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Integer not equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 45678);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Boolean not equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", true);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "azeRTY");
    variableNode.put("operation", "equalsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String not equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "HIJKLm");
    variableNode.put("operation", "notEqualsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String equals without value
    variableNode.removeAll();
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String equals with non existing value
    variableNode.removeAll();
    variableNode.put("value", "Azerty2");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode);
}

From source file:org.flowable.rest.service.api.runtime.ProcessInstanceQueryResourceTest.java

/**
 * Test querying process instance based on variables. POST query/process-instances
 *///from   w w  w.  j  a v a2 s.  com
@Deployment
public void testQueryProcessInstancesWithVariables() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
            processVariables);

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_QUERY);

    // Process variables
    ObjectNode requestNode = objectMapper.createObjectNode();
    ArrayNode variableArray = objectMapper.createArrayNode();
    ObjectNode variableNode = objectMapper.createObjectNode();
    variableArray.add(variableNode);
    requestNode.set("variables", variableArray);

    // String equals
    variableNode.put("name", "stringVar");
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Integer equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 67890);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Boolean equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", false);
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String not equals
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "ghijkl");
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Integer not equals
    variableNode.removeAll();
    variableNode.put("name", "intVar");
    variableNode.put("value", 45678);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // Boolean not equals
    variableNode.removeAll();
    variableNode.put("name", "booleanVar");
    variableNode.put("value", true);
    variableNode.put("operation", "notEquals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "azeRTY");
    variableNode.put("operation", "equalsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String not equals ignore case
    variableNode.removeAll();
    variableNode.put("name", "stringVar");
    variableNode.put("value", "HIJKLm");
    variableNode.put("operation", "notEqualsIgnoreCase");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String equals without value
    variableNode.removeAll();
    variableNode.put("value", "Azerty");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());

    // String equals with non existing value
    variableNode.removeAll();
    variableNode.put("value", "Azerty2");
    variableNode.put("operation", "equals");
    assertResultsPresentInPostDataResponse(url, requestNode);
}

From source file:scott.barleyrs.rest.AdminService.java

private JsonNode toJsonSchema(ObjectMapper mapper, String namespace, EntityType entityType) {
    ObjectNode schemaRoot = mapper.createObjectNode();
    schemaRoot.put("title",
            "JSON Schema for namepsace " + namespace + " and entity " + entityType.getInterfaceName());
    schemaRoot.put("type", "object");
    /*//from ww w . j  a  v a 2 s.  c  o m
     * required section.
     */
    ArrayNode required = mapper.createArrayNode();
    for (NodeType nodeType : entityType.getNodeTypes()) {
        if (nodeType.isMandatory()) {
            required.add(nodeType.getName());
        }
    }
    schemaRoot.set("required", required);

    /*
     * properties section
     */
    ObjectNode properties = mapper.createObjectNode();
    for (NodeType nodeType : entityType.getNodeTypes()) {
        if (nodeType.getEnumSpec() != null) {
            ObjectNode prop = mapper.createObjectNode();
            prop.put("type", toJSONSchemaType(nodeType.getJavaType()));
            prop.set("enum", enumValuesAsJsonArray(mapper, nodeType.getEnumSpec()));
            properties.set(nodeType.getName(), prop);
        } else if (nodeType.getJavaType() != null) {
            ObjectNode prop = mapper.createObjectNode();
            prop.put("type", toJSONSchemaType(nodeType.getJavaType()));
            properties.set(nodeType.getName(), prop);
        } else if (nodeType.getColumnName() != null && nodeType.getRelationInterfaceName() != null) {
            ObjectNode prop = mapper.createObjectNode();
            prop.put("type", "string");
            properties.set(nodeType.getName(), prop);
        }
    }
    schemaRoot.set("properties", properties);
    return schemaRoot;
}

From source file:org.apache.taverna.examples.JsonExport.java

protected ObjectNode toJson(Workflow workflow) {
    ObjectNode wf = mapper.createObjectNode();

    wf.putPOJO("id", uriTools.relativeUriForBean(workflow, workflow.getParent()));

    wf.put("name", workflow.getName());
    wf.put("revisions", toJson(workflow.getCurrentRevision()));

    ArrayNode processors = mapper.createArrayNode();
    for (Processor p : workflow.getProcessors()) {
        processors.add(toJson(p));
    }/*from www  .java  2  s  .c om*/
    addPorts(workflow, wf);
    wf.put("processors", processors);

    ArrayNode datalinks = mapper.createArrayNode();
    for (DataLink link : workflow.getDataLinks()) {
        datalinks.add(toJson(link));
    }
    wf.put("datalinks", datalinks);

    ArrayNode controlLinks = mapper.createArrayNode();
    for (ControlLink link : workflow.getControlLinks()) {
        controlLinks.add(toJson(link));
    }
    wf.put("controllinks", controlLinks);

    wf.putAll(annotations(workflow));

    return wf;
}

From source file:org.flowable.rest.dmn.service.api.decision.DmnRuleServiceResourceTest.java

@DmnDeploymentAnnotation(resources = { "org/flowable/rest/dmn/service/api/decision/multi-hit.dmn" })
public void testExecutionDecisionSingleResultViolated() throws Exception {
    // Add decision key
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("decisionKey", "decision1");

    // add input variable
    ArrayNode variablesNode = objectMapper.createArrayNode();
    ObjectNode variableNode = objectMapper.createObjectNode();
    variableNode.put("name", "inputVariable1");
    variableNode.put("type", "integer");
    variableNode.put("value", 5);
    variablesNode.add(variableNode);

    requestNode.set("inputVariables", variablesNode);

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX
            + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_RULE_SERVICE_EXECUTE_SINGLE_RESULT));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    executeRequest(httpPost, HttpStatus.SC_INTERNAL_SERVER_ERROR);
}

From source file:com.redhat.lightblue.ResponseTest.java

@Test
public void testWithErrors() {
    ObjectNode objNode = JsonObject.getFactory().objectNode();
    ArrayNode arr = JsonObject.getFactory().arrayNode();

    for (Error err : getPopulatedErrors(3)) {
        arr.add(err.toJson());
    }/*from   ww w  .ja  v a  2s . c om*/

    objNode.set("errors", arr);

    builder.withErrors(arr);

    for (int i = 0; i < builder.buildResponse().getErrors().size(); i++) {
        Error e = builder.buildResponse().getErrors().get(i);
        assertTrue(e.getErrorCode().equals(getPopulatedErrors(3).get(i).getErrorCode()));
    }
}

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

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectMapper mapper = Mapper.getInstance();
    ObjectNode node = mapper.createObjectNode();

    if (this.parent != null && this.parent.size() > 0) {
        if (version.equals(TCAPIVersion.V095) && this.getParent().size() > 1) {
            throw new IncompatibleTCAPIVersion("Version " + TCAPIVersion.V095.toString()
                    + " doesn't support lists of activities (parent)");
        }/* w w  w  .  j a  va 2 s .c  om*/

        if (version.equals(TCAPIVersion.V095)) {
            node.put("parent", this.getParent().get(0).toJSONNode(version));
        } else {
            ArrayNode parent = mapper.createArrayNode();
            node.put("parent", parent);

            for (Activity element : this.getParent()) {
                parent.add(element.toJSONNode(version));
            }
        }
    }
    if (this.grouping != null && this.grouping.size() > 0) {
        if (version.equals(TCAPIVersion.V095) && this.getGrouping().size() > 1) {
            throw new IncompatibleTCAPIVersion("Version " + TCAPIVersion.V095.toString()
                    + " doesn't support lists of activities (grouping)");
        }

        if (version.equals(TCAPIVersion.V095)) {
            node.put("grouping", this.getGrouping().get(0).toJSONNode(version));
        } else {
            ArrayNode grouping = mapper.createArrayNode();
            node.put("grouping", grouping);

            for (Activity element : this.getGrouping()) {
                grouping.add(element.toJSONNode(version));
            }
        }
    }
    if (this.other != null && this.other.size() > 0) {
        if (version.equals(TCAPIVersion.V095) && this.getOther().size() > 1) {
            throw new IncompatibleTCAPIVersion(
                    "Version " + TCAPIVersion.V095.toString() + " doesn't support lists of activities (other)");
        }

        if (version.equals(TCAPIVersion.V095)) {
            node.put("other", this.getGrouping().get(0).toJSONNode(version));
        } else {
            ArrayNode other = mapper.createArrayNode();
            node.put("other", other);

            for (Activity element : this.getOther()) {
                other.add(element.toJSONNode(version));
            }
        }
    }
    if (this.category != null && this.category.size() > 0) {
        if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
            ArrayNode category = mapper.createArrayNode();
            node.put("category", category);

            for (Activity element : this.getCategory()) {
                category.add(element.toJSONNode(version));
            }
        } else {
            throw new IncompatibleTCAPIVersion(
                    "Version " + version.toString() + " doesn't support the category context activity");
        }
    }

    return node;
}