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.github.restdriver.matchers.WithSize.java

@Override
public boolean matchesSafely(JsonNode node) {

    if (!node.isArray()) {
        return false;
    }//from  w  w w . j a  v  a 2 s  . c om

    return matcher.matches(node.size());

}

From source file:io.sqp.schemamatcher.fieldmatchers.ItemsSchemaArrayMatcher.java

public ItemsSchemaArrayMatcher(JsonNode schemaArray, AdditionalItemsField additionalField) {
    int numSchemas = schemaArray.size();
    _schemaMatchers = new SchemaMatcher[numSchemas];
    for (int i = 0; i < numSchemas; i++) {
        _schemaMatchers[i] = new SchemaMatcher(schemaArray.get(i));
    }// www  .  j a  v  a2 s . c  om
    _additionalField = additionalField;
}

From source file:edu.berkeley.ground.postgres.dao.core.PostgresEdgeDao.java

@Override
protected Edge retrieve(String sql, Object field) throws GroundException {
    JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(dbSource, sql));

    if (json.size() == 0) {
        throw new GroundException(ExceptionType.ITEM_NOT_FOUND, this.getType().getSimpleName(),
                field.toString());//from ww w . ja  v  a2s . c  om
    }

    Edge edge = Json.fromJson(json.get(0), Edge.class);
    long id = edge.getId();
    return new Edge(id, edge.getName(), edge.getSourceKey(), edge.getFromNodeId(), edge.getToNodeId(),
            super.postgresTagDao.retrieveFromDatabaseByItemId(id));
}

From source file:com.basistech.rosette.dm.json.plain.NameTest.java

@Test
public void name() throws Exception {
    List<Name> names = Lists.newArrayList();
    Name.Builder builder = new Name.Builder("Fred");
    names.add(builder.build());/*w  ww .  j  a va  2s.c  o  m*/
    builder = new Name.Builder("George");
    builder.languageOfOrigin(LanguageCode.ENGLISH).script(ISO15924.Latn).languageOfUse(LanguageCode.FRENCH);
    names.add(builder.build());
    ObjectMapper mapper = objectMapper();
    String json = mapper.writeValueAsString(names);
    // one way to inspect the works is to read it back in _without_ our customized mapper.
    ObjectMapper plainMapper = new ObjectMapper();
    JsonNode tree = plainMapper.readTree(json);
    assertTrue(tree.isArray());
    assertEquals(2, tree.size());
    JsonNode node = tree.get(0);
    assertTrue(node.has("text"));
    assertEquals("Fred", node.get("text").asText());
    assertFalse(node.has("script"));
    assertFalse(node.has("languageOfOrigin"));
    assertFalse(node.has("languageOfUse"));

    List<Name> readBack = mapper.readValue(json, new TypeReference<List<Name>>() {
    });
    assertEquals(names, readBack);
}

From source file:edu.berkeley.ground.postgres.dao.usage.PostgresLineageEdgeVersionDao.java

@Override
public LineageEdgeVersion retrieveFromDatabase(long id) throws GroundException {
    String sql = String.format(SqlConstants.SELECT_STAR_BY_ID, "lineage_edge_version", id);
    JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(dbSource, sql));

    if (json.size() == 0) {
        throw new GroundException(ExceptionType.VERSION_NOT_FOUND, this.getType().getSimpleName(),
                String.format("%d", id));
    }//from  w  w  w. jav  a 2 s  .  com

    LineageEdgeVersion lineageEdgeVersion = Json.fromJson(json.get(0), LineageEdgeVersion.class);
    RichVersion richVersion = super.retrieveFromDatabase(id);

    return new LineageEdgeVersion(id, richVersion, lineageEdgeVersion);
}

From source file:fr.gouv.vitam.utils.json.JsonHandler.java

/**
 * node should have only one property ; simple value is allowed
 *
 * @param nodeName//  w w  w. j ava  2s  . c  o  m
 * @param node
 * @return the couple property name and property value
 * @throws InvalidParseOperationException
 */
public static final Entry<String, JsonNode> checkLaxUnicity(final String nodeName, final JsonNode node)
        throws InvalidParseOperationException {
    if (node == null || node.isMissingNode()) {
        throw new InvalidParseOperationException(
                "The current Node is missing(empty): " + nodeName + ":" + node);
    }
    if (node.isValueNode()) {
        // already one node
        return new Entry<String, JsonNode>() {
            @Override
            public JsonNode setValue(final JsonNode value) {
                throw new IllegalArgumentException("Cannot set Value");
            }

            @Override
            public JsonNode getValue() {
                return node;
            }

            @Override
            public String getKey() {
                return null;
            }
        };
    }
    final int size = node.size();
    if (size > 1) {
        throw new InvalidParseOperationException(
                "More than one element in current Node: " + nodeName + ":" + node);
    }
    if (size == 0) {
        throw new InvalidParseOperationException(
                "Not enough element (0) in current Node: " + nodeName + ":" + node);
    }
    final Iterator<Entry<String, JsonNode>> iterator = node.fields();
    return iterator.next();
}

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

/**
 * Test if @SchemaIgnore works correctly
 *///www . jav a2  s .c o m
public void testGenerateSchema() {

    JsonNode schema = v4generator.createSchema(Sale.class);
    //System.out.println(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(schema));
    JsonNode properties = schema.get("properties");
    assertEquals(1, properties.size());

    schema = v4generator.createSchema(SaleItem.class);
    //System.out.println(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(schema));
    properties = schema.get("properties");
    assertEquals(2, properties.size());
}

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

private Coordinate[] parseLineString(JsonNode array) {
    Coordinate[] points = new Coordinate[array.size()];
    for (int i = 0; i != array.size(); ++i) {
        points[i] = parseCoordinate(array.get(i));
    }//ww  w  .j a va 2s .  c o m
    return points;
}

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

private LineString[] parseLineStrings(JsonNode array) {
    LineString[] strings = new LineString[array.size()];
    for (int i = 0; i != array.size(); ++i) {
        strings[i] = gf.createLineString(parseLineString(array.get(i)));
    }// w w  w.j a  v  a 2s .  co m
    return strings;
}

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

private Geometry[] parseGeometries(JsonNode arrayOfGeoms) {
    Geometry[] items = new Geometry[arrayOfGeoms.size()];
    for (int i = 0; i != arrayOfGeoms.size(); ++i) {
        items[i] = parseGeometry(arrayOfGeoms.get(i));
    }/*from w ww. j  a v  a  2s.c o  m*/
    return items;
}