Example usage for com.fasterxml.jackson.databind JsonNode size

List of usage examples for com.fasterxml.jackson.databind JsonNode size

Introduction

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

Prototype

public int size() 

Source Link

Usage

From source file:com.crossedstreams.desktop.website.JsonParser.java

private UrlGroup buildGroup(JsonNode groupJson) {
    String label = groupJson.path("label").asText();
    UrlExpectation expectation = buildExpectation(groupJson.path("expect"), UrlExpectation.DEFAULT_EXPECTATION);
    JsonNode urls = groupJson.path("urls");
    List<UrlDefinition> defs = new ArrayList<UrlDefinition>(urls.size());
    for (JsonNode urlNode : urls) {
        defs.add(buildUrlDef(urlNode, expectation));
    }/*from w  w  w  .j  a v a2  s . com*/
    return new UrlGroup(label, expectation, defs);
}

From source file:org.eel.kitchen.jsonschema.keyword.AdditionalItemsKeywordValidator.java

public AdditionalItemsKeywordValidator(final JsonNode schema) {
    super("additionalItems", NodeType.ARRAY);
    additionalOK = schema.get(keyword).asBoolean(true);

    if (additionalOK)
        return;/*www .  j av  a2  s  .  c o m*/

    final JsonNode items = schema.path("items");

    if (items.isArray())
        itemsCount = items.size();
    else
        additionalOK = true;
}

From source file:com.infinities.keystone4j.admin.v3.role_assignment.RoleAssignmentResourceTest.java

@Test
public void testListRoleAssignment() throws JsonProcessingException, IOException {
    Response response = target("/v3/role_assignments").register(JacksonFeature.class)
            .register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    String ret = response.readEntity(String.class);
    JsonNode node = JsonUtils.convertToJsonNode(ret);
    System.err.println(ret);/*from w w w .  ja  v  a2s  .co  m*/
    JsonNode rolesJ = node.get("role_assignments");
    assertEquals(4, rolesJ.size());
}

From source file:piazza.services.ingest.util.GeoJsonDeserializer.java

private Polygon[] parsePolygons(JsonNode arrayOfPolygons) {
    Polygon[] polygons = new Polygon[arrayOfPolygons.size()];
    for (int i = 0; i != arrayOfPolygons.size(); ++i) {
        polygons[i] = parsePolygonCoordinates(arrayOfPolygons.get(i));
    }//from  ww w .j av a 2s  .  c  o m
    return polygons;
}

From source file:piazza.services.ingest.util.GeoJsonDeserializer.java

private LinearRing[] parseInteriorRings(JsonNode arrayOfRings) {
    LinearRing[] rings = new LinearRing[arrayOfRings.size() - 1];
    for (int i = 1; i < arrayOfRings.size(); ++i) {
        rings[i - 1] = gf.createLinearRing(parseLineString(arrayOfRings.get(i)));
    }/* w  w w  .ja v a  2 s.c om*/
    return rings;
}

From source file:com.auditbucket.test.functional.TestWebServiceIntegration.java

public void jsonReadFiles() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(authA);
    ObjectMapper mapper = new ObjectMapper();
    String filename = "//tmp/new-trainprofiles.json";
    InputStream is = new FileInputStream(filename);
    JsonNode node = mapper.readTree(is);

    System.out.println("node Count = " + node.size());
    HttpClient httpclient = new DefaultHttpClient();
    String url = "http://localhost:8080/ab-engine/track/header/new";
    for (JsonNode profile : node.elements().next()) {
        HttpPost auditPost = new HttpPost(url);
        auditPost.addHeader("content-type", "application/json");
        auditPost.addHeader("Authorization", "Basic bWlrZToxMjM=");
        MetaInputBean inputBean = new MetaInputBean("capacity", "system", "TrainProfile", DateTime.now(),
                profile.get("profileID").asText());
        LogInputBean log = new LogInputBean("moira", null, profile.toString());
        inputBean.setLog(log);//from w  w  w .  j  a v  a  2s.  c o m
        log.setForceReindex(true);
        StringEntity json = new StringEntity(mapper.writeValueAsString(inputBean));
        auditPost.setEntity(json);
        HttpResponse response = httpclient.execute(auditPost);

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }
    }
}

From source file:com.hortonworks.pso.data.generator.RecordGenerator.java

public RecordGenerator(JsonNode node) {
    // This node should be either the "root" node OR the "fields" node.
    delimiter = node.get("delimiter").asText();

    JsonNode fieldsNode = node.get("fields");

    for (int i = 0; i < fieldsNode.size(); i++) {
        JsonNode fieldNode = fieldsNode.get(i);
        if (fieldNode.has("string")) {
            FieldType field = new StringField(fieldNode.get("string"));
            addFields(field);//from  ww  w.ja  va 2s.com
        } else if (fieldNode.has("number")) {
            FieldType field = new NumberField(fieldNode.get("number"));
            addFields(field);
        } else if (fieldNode.has("ip")) {
            FieldType field = new IPAddressField(fieldNode.get("ip"));
            addFields(field);
        } else if (fieldNode.has("boolean")) {
            FieldType field = new BooleanField(fieldNode.get("boolean"));
            addFields(field);
        } else if (fieldNode.has("date")) {
            FieldType field = new DateField(fieldNode.get("date"));
            addFields(field);
        } else if (fieldNode.has("null")) {
            FieldType field = new NullField(fieldNode.get("null"));
            addFields(field);
        } else if (fieldNode.has("start.stop")) {
            StartStopFields fields = new StartStopFields(fieldNode.get("start.stop"));
            addFields(fields.getStartField());
            addFields(fields.getStopField());
        } else if (fieldNode.has("nested")) {
            FieldType field = new NestedField(fieldNode.get("nested"));
            addFields(field);
        }
    }
}

From source file:org.springframework.tuple.JsonStringToTupleConverter.java

private List<Object> nodeToList(JsonNode node) throws JsonProcessingException {
    List<Object> list = new ArrayList<Object>(node.size());
    for (int i = 0; i < node.size(); i++) {
        JsonNode item = node.get(i);/*from w w w  . j a va2  s  .  co  m*/
        if (item.isObject()) {
            list.add(convert(item.toString()));
        } else if (item.isArray()) {
            list.add(nodeToList(item));
        } else if (item.isNull()) {
            list.add(null);
        } else if (item.isBoolean()) {
            list.add(item.booleanValue());
        } else if (item.isNumber()) {
            list.add(item.numberValue());
        } else {
            list.add(mapper.treeToValue(item, Object.class));
        }
    }
    return list;
}

From source file:com.github.fge.jsonschema.keyword.digest.draftv3.DraftV3DependenciesDigester.java

@Override
public JsonNode digest(final JsonNode schema) {
    final ObjectNode ret = FACTORY.objectNode();

    final ObjectNode propertyDeps = FACTORY.objectNode();
    ret.put("propertyDeps", propertyDeps);

    final ArrayNode schemaDeps = FACTORY.arrayNode();
    ret.put("schemaDeps", schemaDeps);

    final List<String> list = Lists.newArrayList();

    final Map<String, JsonNode> map = JacksonUtils.asMap(schema.get(keyword));

    String key;/*  w ww. j  a va 2 s .  com*/
    JsonNode value;
    NodeType type;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        key = entry.getKey();
        value = entry.getValue();
        type = NodeType.getNodeType(value);
        switch (type) {
        case OBJECT:
            list.add(key);
            break;
        case ARRAY:
            final JsonNode node = sortedSet(value);
            if (node.size() != 0)
                propertyDeps.put(key, node);
            break;
        case STRING:
            propertyDeps.put(key, FACTORY.arrayNode().add(value.textValue()));
        }
    }

    for (final String s : Ordering.natural().sortedCopy(list))
        schemaDeps.add(s);

    return ret;
}

From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java

/** Recursive function to pull out potentially nested properties
 * @param property/*from   w  ww. j a  v  a2  s  .  co  m*/
 * @return
 */
protected static Either<Object, Object[]> denestProperties(final JsonNode property) {
    if (property.isArray()) { // (Arrays of objects (except length 1) are currently discarded here, no support for cardinality, see above)
        if (1 == property.size()) { // (this is what all the existing properties look like after conversion to graphson)
            return denestProperties(property.get(0));
        } else {
            return Either.right(Optionals.streamOf(property.iterator(), false).map(j -> jsonNodeToObject(j))
                    .filter(j -> null != j).toArray());
        }
    } else if (property.isObject()) {
        return denestProperties(property.get(GraphAnnotationBean.value));
    } else {
        return Either.left(jsonNodeToObject(property));
    }
}