Example usage for com.fasterxml.jackson.databind.node ArrayNode size

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode size.

Prototype

public int size() 

Source Link

Usage

From source file:com.siemens.sw360.datahandler.common.JacksonUtils.java

public static int arrayPosition(ArrayNode array, String needle) {
    for (int i = 0; i < array.size(); i++) {
        JsonNode jsonNode = array.get(i);
        if (jsonNode.isTextual() && needle.equals(jsonNode.textValue())) {
            return i;
        }// ww w  .j ava  2s.com
    }
    return -1;
}

From source file:com.redhat.lightblue.query.ProjectionList.java

public static ProjectionList fromJson(ArrayNode node) {
    ArrayList<Projection> list = new ArrayList<>(node.size());
    for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) {
        list.add(BasicProjection.fromJson((ObjectNode) itr.next()));
    }//w w  w  .j a  va 2  s.c  o m
    return new ProjectionList(list);
}

From source file:com.redhat.lightblue.query.CompositeSortKey.java

/**
 * Parses a composite sort key using the json array node
 *//*from ww w . j a v a2s .com*/
public static CompositeSortKey fromJson(ArrayNode node) {
    ArrayList<SortKey> l = new ArrayList<>(node.size());
    for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) {
        l.add(SortKey.fromJson((ObjectNode) itr.next()));
    }
    return new CompositeSortKey(l);
}

From source file:com.redhat.lightblue.query.UpdateExpressionList.java

/**
 * Parses an update expression list using the given json object
 *///w w w.  ja  v  a 2 s  .c  o  m
public static UpdateExpressionList fromJson(ArrayNode node) {
    ArrayList<PartialUpdateExpression> list = new ArrayList<>(node.size());
    for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) {
        list.add(PartialUpdateExpression.fromJson((ObjectNode) itr.next()));
    }
    return new UpdateExpressionList(list);
}

From source file:com.baasbox.service.query.JsonTree.java

public static JsonNode write(JsonNode json, PartsParser pp, JsonNode data) throws MissingNodeException {
    JsonNode root = json;// ww  w  .  java  2  s  .  c  o  m
    for (Part p : pp.parts()) {
        if (p.equals(pp.last())) {
            break;
        }
        if (p instanceof PartsLexer.ArrayField) {
            int index = ((PartsLexer.ArrayField) p).arrayIndex;
            root = root.path(p.getName()).path(index);
        } else if (p instanceof PartsLexer.Field) {
            root = root.path(p.getName());
        }
    }
    if (root.isMissingNode()) {
        throw new MissingNodeException(pp.treeFields());
    }
    Part last = pp.last();

    if (last instanceof PartsLexer.ArrayField) {
        PartsLexer.ArrayField arr = (PartsLexer.ArrayField) last;
        int index = arr.arrayIndex;
        root = root.path(last.getName());
        ArrayNode arrNode = (ArrayNode) root;
        if (arrNode.size() <= index) {
            arrNode.add(data);
        } else {
            arrNode.set(index, data);
        }
        return root;

    } else {
        try {
            ((ObjectNode) root).put(last.getName(), data);
        } catch (Exception e) {
            throw new MissingNodeException(pp.treeFields());
        }
        return root.get(last.getName());
    }

}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static List<String> stringListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<String>(0);
    JsonNode value = node.get(key);// w  w w .  j a  v a2s. co m
    if (value == null)
        return new ArrayList<String>(0);

    ArrayNode arrayNode = (ArrayNode) value;
    ArrayList<String> result = new ArrayList<String>(arrayNode.size());
    for (JsonNode innerNode : arrayNode) {
        result.add(innerNode.textValue());
    }
    return result;
}

From source file:com.syncedsynapse.kore2.utils.JsonUtils.java

public static List<Integer> integerListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<Integer>(0);
    JsonNode value = node.get(key);/*from  w  w  w .j  av  a  2s  . c o m*/
    if (value == null)
        return new ArrayList<Integer>(0);

    ArrayNode arrayNode = (ArrayNode) value;
    ArrayList<Integer> result = new ArrayList<Integer>(arrayNode.size());
    for (JsonNode innerNode : arrayNode) {
        result.add(innerNode.asInt());
    }
    return result;
}

From source file:org.xbmc.kore.utils.JsonUtils.java

public static List<String> stringListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<String>(0);
    JsonNode value = node.get(key);//from w  w  w  . j a  va2s . c  o m
    if (value == null)
        return new ArrayList<String>(0);

    ArrayList<String> result;
    if (value.isArray()) {
        ArrayNode arrayNode = (ArrayNode) value;
        result = new ArrayList<String>(arrayNode.size());
        for (JsonNode innerNode : arrayNode) {
            result.add(innerNode.textValue());
        }
    } else {
        // This isn't exactly what we're expecting, but we can return the text value
        result = new ArrayList<String>(1);
        result.add(value.textValue());
    }
    return result;
}

From source file:org.xbmc.kore.utils.JsonUtils.java

public static List<Integer> integerListFromJsonNode(JsonNode node, String key) {
    if (node == null)
        return new ArrayList<Integer>(0);
    JsonNode value = node.get(key);/*from w  w  w .  j a va  2  s  . c o m*/
    if (value == null)
        return new ArrayList<Integer>(0);

    ArrayList<Integer> result;
    if (value.isArray()) {
        ArrayNode arrayNode = (ArrayNode) value;
        result = new ArrayList<Integer>(arrayNode.size());
        for (JsonNode innerNode : arrayNode) {
            result.add(innerNode.asInt());
        }
    } else {
        result = new ArrayList<Integer>(1);
        result.add(value.asInt());
    }
    return result;
}

From source file:com.palominolabs.testutil.JsonAssert.java

public static void assertJsonArrayEquals(String msg, ArrayNode expected, ArrayNode actual) {

    assertEquals(msg + "/array length", expected.size(), actual.size());

    for (int i = 0; i < expected.size(); i++) {
        assertJsonNodeEquals(msg + "/index <" + i + ">", expected.get(i), actual.get(i));
    }// w w  w.ja  v  a  2 s  .c  om
}