Example usage for com.fasterxml.jackson.databind ObjectMapper createArrayNode

List of usage examples for com.fasterxml.jackson.databind ObjectMapper createArrayNode

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper createArrayNode.

Prototype

@Override
public ArrayNode createArrayNode() 

Source Link

Document

Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)

Usage

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void includeElementFieldWithWeight(String dbName, String field_name, String namespace,
        String elementName, double weight, String attrNS_URI, String attr_localname, String attr_value)
        throws Exception {

    ObjectMapper mapper = new ObjectMapper();
    //         ObjectNode mainNode = mapper.createObjectNode();
    ObjectNode childNode = mapper.createObjectNode();
    ArrayNode arrNode = mapper.createArrayNode();
    ObjectNode childNodeObject = mapper.createObjectNode();
    childNodeObject.put("namespace-uri", namespace);
    childNodeObject.put("localname", elementName);
    childNodeObject.put("weight", weight);
    // These 3 are new fields that have been added as of 8.0.2 from 03/20/2015 in the Management API.
    childNodeObject.put("attribute-namespace-uri", attrNS_URI);
    childNodeObject.put("attribute-localname", attr_localname);
    childNodeObject.put("attribute-value", attr_value);
    arrNode.add(childNodeObject);//w w  w . j a  v  a 2s.  com
    childNode.putArray("included-element").addAll(arrNode);

    //System.out.println( childNode.toString());
    setDatabaseFieldProperties(dbName, field_name, "included-element", childNode);

}

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void addGeospatialElementPairIndexes(String dbName, String parentNamespaceUri,
        String parentLocalName, String latNamespace, String latLocalname, String longNamespace,
        String longLocalname, String coordinateSystem, boolean rangeValuePositions, String invalidValues)
        throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    //      ObjectNode mainNode = mapper.createObjectNode();
    ObjectNode childNode = mapper.createObjectNode();
    ArrayNode childArray = mapper.createArrayNode();
    ObjectNode childNodeObject = mapper.createObjectNode();
    childNodeObject.put("parent-namespace-uri", parentNamespaceUri);
    childNodeObject.put("parent-localname", parentLocalName);
    childNodeObject.put("latitude-namespace-uri", latNamespace);
    childNodeObject.put("latitude-localname", latLocalname);
    childNodeObject.put("longitude-namespace-uri", latNamespace);
    childNodeObject.put("longitude-localname", longLocalname);
    childNodeObject.put("coordinate-system", coordinateSystem);
    childNodeObject.put("range-value-positions", false);
    childNodeObject.put("invalid-values", invalidValues);
    childArray.add(childNodeObject);// w w  w  . java 2 s.c  o  m
    childNode.putArray("geospatial-element-pair-index").addAll(childArray);
    //         mainNode.put("geospatial-element-pair-indexes", childNode);
    //         System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString());
    setDatabaseProperties(dbName, "geospatial-element-pair-index", childNode);
}

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void addGeospatialElementAttributePairIndexes(String dbName, String parentNamespaceUri,
        String parentLocalName, String latNamespace, String latLocalname, String longNamespace,
        String longLocalname, String coordinateSystem, boolean rangeValuePositions, String invalidValues)
        throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    //         ObjectNode mainNode = mapper.createObjectNode();
    ObjectNode childNode = mapper.createObjectNode();
    ArrayNode childArray = mapper.createArrayNode();
    ObjectNode childNodeObject = mapper.createObjectNode();
    childNodeObject.put("parent-namespace-uri", parentNamespaceUri);
    childNodeObject.put("parent-localname", parentLocalName);
    childNodeObject.put("latitude-namespace-uri", latNamespace);
    childNodeObject.put("latitude-localname", latLocalname);
    childNodeObject.put("longitude-namespace-uri", latNamespace);
    childNodeObject.put("longitude-localname", longLocalname);
    childNodeObject.put("coordinate-system", coordinateSystem);
    childNodeObject.put("range-value-positions", false);
    childNodeObject.put("invalid-values", invalidValues);
    childArray.add(childNodeObject);//w  w  w.j a  v a  2s  . com
    childNode.putArray("geospatial-element-attribute-pair-index").addAll(childArray);
    //         mainNode.put("geospatial-element-attribute-pair-indexes", childNode);
    //         System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString());
    setDatabaseProperties(dbName, "geospatial-element-attribute-pair-index", childNode);
}

From source file:la.alsocan.jsonshapeshifter.Transformation.java

private void resolveNode(ObjectMapper om, SchemaNode node, JsonNode parentNode, JsonNode payload,
        List<Integer> pointerContext) {
    switch (node.getType()) {
    case OBJECT://from   www  .j ava  2 s .  c o m
        ObjectNode oNode = om.createObjectNode();
        ((SchemaObjectNode) node).getChildren().stream().forEach((tChildNode) -> {
            resolveNode(om, tChildNode, oNode, payload, pointerContext);
        });
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).set(node.getName(), oNode);
        } else {
            ((ArrayNode) parentNode).add(oNode);
        }
        break;
    case ARRAY:
        ArrayNode aNode = om.createArrayNode();
        SchemaNode tChildNode = ((SchemaArrayNode) node).getChild();
        int index = 0;
        pointerContext.add(index);
        Iterator<JsonNode> it = (Iterator<JsonNode>) resolveValue(node, payload, pointerContext);
        while (it.hasNext()) {
            it.next();
            resolveNode(om, tChildNode, aNode, payload, pointerContext);
            pointerContext.set(pointerContext.size() - 1, ++index);
        }
        pointerContext.remove(pointerContext.size() - 1);
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).set(node.getName(), aNode);
        } else {
            ((ArrayNode) parentNode).add(aNode);
        }
        break;
    case BOOLEAN:
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).put(node.getName(),
                    (Boolean) resolveValue(node, payload, pointerContext));
        } else {
            ((ArrayNode) parentNode).add((Boolean) resolveValue(node, payload, pointerContext));
        }
        break;
    case INTEGER:
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).put(node.getName(),
                    (Integer) resolveValue(node, payload, pointerContext));
        } else {
            ((ArrayNode) parentNode).add((Integer) resolveValue(node, payload, pointerContext));
        }
        break;
    case NUMBER:
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).put(node.getName(), (Double) resolveValue(node, payload, pointerContext));
        } else {
            ((ArrayNode) parentNode).add((Double) resolveValue(node, payload, pointerContext));
        }
        break;
    case NULL:
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).putNull(node.getName());
        } else {
            ((ArrayNode) parentNode).addNull();
        }
        break;
    case STRING:
        if (parentNode.isObject()) {
            ((ObjectNode) parentNode).put(node.getName(), (String) resolveValue(node, payload, pointerContext));
        } else {
            ((ArrayNode) parentNode).add((String) resolveValue(node, payload, pointerContext));
        }
        break;
    }
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void addRangeElementIndex(String dbName, String[][] rangeElements) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode mainNode = mapper.createObjectNode();

    ArrayNode childArray = mapper.createArrayNode();
    int nRowsLen = rangeElements.length;
    int j = 0;// w ww  . j a  v  a2 s .com
    for (int i = 0; i < nRowsLen; i++) {
        ObjectNode childNodeObject = mapper.createObjectNode();
        childNodeObject.put("scalar-type", rangeElements[i][j++]);
        childNodeObject.put("namespace-uri", rangeElements[i][j++]);
        childNodeObject.put("localname", rangeElements[i][j++]);
        childNodeObject.put("collation", rangeElements[i][j++]);
        if (rangeElements[i][j].equalsIgnoreCase("false"))
            childNodeObject.put("range-value-positions", false);
        else
            childNodeObject.put("range-value-positions", true);
        j++;
        childNodeObject.put("invalid-values", rangeElements[i][j++]);
        /* if new field elements are to be added, then:
         * 1) Increment value of j
         * 2) add them below here using childNodeObject.put("FIELD-NAME", rangeElements[i][j++]);
        */
        childArray.add(childNodeObject);
        j = 0;
    }
    mainNode.putArray("range-element-index").addAll(childArray);
    setDatabaseProperties(dbName, "range-element-index", mainNode);
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void addRangePathIndex(String dbName, String[][] rangePaths) throws Exception {

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode childNode = mapper.createObjectNode();
    ArrayNode childArray = mapper.createArrayNode();

    int nRowsLen = rangePaths.length;
    int j = 0;/*from  ww  w .  j a v a 2 s  .com*/
    for (int i = 0; i < nRowsLen; i++) {
        ObjectNode childNodeObject = mapper.createObjectNode();
        childNodeObject.put("scalar-type", rangePaths[i][j++]);
        childNodeObject.put("path-expression", rangePaths[i][j++]);
        childNodeObject.put("collation", rangePaths[i][j++]);
        childNodeObject.put("invalid-values", rangePaths[i][j++]);

        if (rangePaths[i][j].equalsIgnoreCase("false"))
            childNodeObject.put("range-value-positions", false);
        else
            childNodeObject.put("range-value-positions", true);
        /* if new field elements are to be added, then:
         * 1) Increment value of j
         * 2) add them below here using childNodeObject.put("FIELD-NAME", rangePaths[i][j++]);
        */

        childArray.add(childNodeObject);
        j = 0;
    }
    childNode.putArray("range-path-index").addAll(childArray);

    setDatabaseProperties(dbName, "range-path-index", childNode);
}

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void createRESTUser(String usrName, String pass, String... roleNames) {
    try {//from w  ww . j a v a  2s .  co m
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));
        HttpGet getrequest = new HttpGet("http://localhost:8002" + "/manage/v2/users/" + usrName);
        HttpResponse resp = client.execute(getrequest);

        if (resp.getStatusLine().getStatusCode() == 200) {
            System.out.println("User already exist");
        } else {
            System.out.println("User dont exist");
            client = new DefaultHttpClient();
            client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                    new UsernamePasswordCredentials("admin", "admin"));

            ObjectMapper mapper = new ObjectMapper();
            ObjectNode mainNode = mapper.createObjectNode();
            //         ObjectNode childNode = mapper.createObjectNode();
            ArrayNode childArray = mapper.createArrayNode();
            mainNode.put("user-name", usrName);
            mainNode.put("description", "user discription");
            mainNode.put("password", pass);
            for (String rolename : roleNames)
                childArray.add(rolename);
            mainNode.withArray("role").addAll(childArray);
            //System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString());
            System.out.println(mainNode.toString());
            HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/users?format=json");
            post.addHeader("Content-type", "application/json");
            post.setEntity(new StringEntity(mainNode.toString()));

            HttpResponse response = client.execute(post);
            HttpEntity respEntity = response.getEntity();
            if (response.getStatusLine().getStatusCode() == 400) {
                System.out.println("User already exist");
            } else if (respEntity != null) {
                // EntityUtils to get the response content
                String content = EntityUtils.toString(respEntity);
                System.out.println(content);
            } else {
                System.out.println("No Proper Response");
            }
        }
    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }
}

From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java

public static void createRESTUserWithPermissions(String usrName, String pass, ObjectNode perm,
        ObjectNode colections, String... roleNames) {
    try {//from   w w  w. j a  va2  s  .com
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));
        HttpGet getrequest = new HttpGet("http://localhost:8002" + "/manage/v2/users/" + usrName);
        HttpResponse resp = client.execute(getrequest);

        if (resp.getStatusLine().getStatusCode() == 200) {
            System.out.println("User already exist");
        } else {
            System.out.println("User dont exist");
            client = new DefaultHttpClient();
            client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                    new UsernamePasswordCredentials("admin", "admin"));

            ObjectMapper mapper = new ObjectMapper();
            ObjectNode mainNode = mapper.createObjectNode();
            //         ObjectNode childNode = mapper.createObjectNode();
            ArrayNode childArray = mapper.createArrayNode();
            mainNode.put("user-name", usrName);
            mainNode.put("description", "user discription");
            mainNode.put("password", pass);
            for (String rolename : roleNames)
                childArray.add(rolename);
            mainNode.withArray("role").addAll(childArray);
            mainNode.setAll(perm);
            mainNode.setAll(colections);
            //System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString());
            System.out.println(mainNode.toString());
            HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/users?format=json");
            post.addHeader("Content-type", "application/json");
            post.setEntity(new StringEntity(mainNode.toString()));

            HttpResponse response = client.execute(post);
            HttpEntity respEntity = response.getEntity();
            if (response.getStatusLine().getStatusCode() == 400) {
                System.out.println("Bad User creation request");
            } else if (respEntity != null) {
                // EntityUtils to get the response content
                String content = EntityUtils.toString(respEntity);
                System.out.println(content);
            } else {
                System.out.println("No Proper Response");
            }
        }
    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }
}

From source file:com.marklogic.client.functionaltest.ConnectedRESTQA.java

public static void includeElementFieldWithWeight(String dbName, String field_name, String namespace,
        String elementName, double weight, String attrNS_URI, String attr_localname, String attr_value)
        throws Exception {

    ObjectMapper mapper = new ObjectMapper();
    //         ObjectNode mainNode = mapper.createObjectNode();
    ObjectNode childNode = mapper.createObjectNode();
    ArrayNode arrNode = mapper.createArrayNode();
    ObjectNode childNodeObject = mapper.createObjectNode();
    childNodeObject.put("namespace-uri", namespace);
    childNodeObject.put("localname", elementName);
    childNodeObject.put("weight", weight);
    // These 3 are new fields that have been added as of 8.0.2 from 03/20/2015 in the Management API.
    childNodeObject.put("attribute-namespace-uri", attrNS_URI);
    childNodeObject.put("attribute-localname", attr_localname);
    childNodeObject.put("attribute-value", attr_value);
    arrNode.add(childNodeObject);/* w w w .  j av  a  2s .  c o  m*/
    childNode.putArray("included-element").addAll(arrNode);
    setDatabaseFieldProperties(dbName, field_name, "included-element", childNode);

}

From source file:org.onosproject.sse.SseTopologyViewMessages.java

private ArrayNode labels(ObjectMapper mapper, String... labels) {
    ArrayNode json = mapper.createArrayNode();
    for (String label : labels) {
        json.add(label);/* w  w  w  .java2 s  .co  m*/
    }
    return json;
}