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:io.sqp.schemamatcher.fieldmatchers.ItemsSchemaArrayMatcher.java

private boolean checkAdditionalItemsAreCompatible(JsonNode schemaArray, AdditionalItemsField otherAdditional) {
    // the matching schema defined more items than this schema. we need to check if we have an additional items
    // field defined, and if it is compatible with the matching schema
    for (int i = _schemaMatchers.length; i < schemaArray.size(); i++) {
        if (!_additionalField.isCompatibleTo(schemaArray.get(i))) {
            return false;
        }//from   w w  w .  j ava  2s.c o m
    }
    // now just check if the additionalFields are compatible to each other
    return _additionalField.isCompatibleTo(otherAdditional);
}

From source file:org.obiba.mica.core.upgrade.Mica220Upgrade.java

private void replacePropertyInSchema(JsonNode schemaNode) {
    JsonNode jsonNode = schemaNode.get("properties").get("access").get("items").get("enum");

    for (int i = 0; i < jsonNode.size(); i++) {
        if (jsonNode.get(i).textValue().equals("biosamples")) {
            ((ArrayNode) jsonNode).remove(i);
            ((ArrayNode) jsonNode).add("bio_samples");
            return;
        }// w w w  .j a  v  a2 s  .co  m
    }
}

From source file:ac.ucy.cs.spdx.service.Compatibility.java

@POST
@Path("/compatible/")
@Consumes(MediaType.TEXT_PLAIN)/*from w  w  w. j a va 2  s.  c  o  m*/
@Produces(MediaType.APPLICATION_JSON)
public String areCompatible(String jsonString) {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode fileNode = null;
    try {
        fileNode = mapper.readTree(jsonString);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    ArrayList<String> licenses = new ArrayList<String>();
    JsonNode licensesJSON = fileNode.get("licenses");
    StringBuilder compatibleJSON = new StringBuilder();

    for (int i = 0; i < licensesJSON.size(); i++) {
        String licenseId = licensesJSON.get(i).get("identifier").toString();
        licenseId = licenseId.substring(1, licenseId.length() - 1);
        licenses.add(licenseId);
    }

    boolean compatible = LicenseCompatibility.areCompatible(licenses.toArray(new String[licenses.size()]));
    boolean adjustable = true;
    ArrayList<License> proposed = new ArrayList<License>();

    if (!compatible) {
        LicenseCompatibility.proposeLicense(licenses.toArray(new String[licenses.size()]));
    }

    if (proposed.isEmpty()) {
        adjustable = false;
    }

    compatibleJSON.append(
            "{\"compatible\":\"" + compatible + "\",\"adjustable\":\"" + adjustable + "\",\"proposals\":[");
    for (License proposal : proposed) {
        compatibleJSON.append("{\"identifier\":\"" + proposal.getIdentifier() + "\"},");
    }

    if (adjustable) {
        compatibleJSON.deleteCharAt(compatibleJSON.length() - 1);
    }

    compatibleJSON.append("]}");
    return compatibleJSON.toString();// {"licenses":[{"identifier":"Apache-2.0"},{"identifier":"MPL-2.0"}]}
}

From source file:com.arantius.tivocommander.ToDo.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (MindRpc.init(this, null)) {
        return;/*from w  w w.  j  a  v a 2  s.  c  o  m*/
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.list_todo);
    setTitle("To Do List");

    mListAdapter = new ShowsAdapter(this);
    ListView lv = getListView();
    lv.setAdapter(mListAdapter);
    lv.setOnItemClickListener(mOnClickListener);
    lv.setLongClickable(true);
    lv.setOnItemLongClickListener(this);

    mDetailCallback = new MindRpcResponseListener() {
        public void onResponse(MindRpcResponse response) {
            setProgressIndicator(-1);

            String itemId = "recording";
            final JsonNode items = response.getBody().path(itemId);

            ArrayList<Integer> slotMap = mRequestSlotMap.get(response.getRpcId());

            for (int i = 0; i < items.size(); i++) {
                int pos = slotMap.get(i);
                JsonNode item = items.get(i);
                mShowData.set(pos, item);
                mShowStatus.set(pos, ShowStatus.LOADED);
            }

            mRequestSlotMap.remove(response.getRpcId());
            mListAdapter.notifyDataSetChanged();
        }
    };

    mIdSequenceCallback = new MindRpcResponseListener() {
        public void onResponse(MindRpcResponse response) {
            JsonNode body = response.getBody();

            setProgressIndicator(-1);

            mShowIds = (ArrayNode) body.findValue("objectIdAndType");
            if (mShowIds == null)
                return;

            for (int i = 0; i < mShowIds.size(); i++) {
                mShowData.add(null);
                mShowStatus.add(ShowStatus.MISSING);
            }
            mListAdapter.notifyDataSetChanged();
        }
    };

    startRequest();
}

From source file:com.spotify.apollo.elide.ElideResourceTest.java

@Test
public void shouldReturnCollectionFromElide() throws Exception {

    Response<ByteString> response = invokeRoute(Request.forUri("/prefix/thing", "GET"));

    JsonNode jsonNode = successfulAsJson(response);

    Set<String> ids = new HashSet<>();
    Set<String> names = new HashSet<>();

    JsonNode data = jsonNode.get("data");

    for (int i = 0; i < data.size(); i++) {
        ids.add(data.get(i).get("id").asText());
        names.add(data.get(i).get("attributes").get("name").asText());
    }/*from w ww .  j  a  va 2  s  .co m*/

    assertThat(ids, is(ImmutableSet.of("1", "2")));
    assertThat(names, is(ImmutableSet.of("flerp", "florpe")));
}

From source file:org.n52.io.geojson.GeoJSONDecoder.java

protected MultiPolygon decodeMultiPolygon(JsonNode node, GeometryFactory fac) throws GeoJSONException {
    JsonNode coordinates = requireCoordinates(node);
    Polygon[] polygons = new Polygon[coordinates.size()];
    for (int i = 0; i < coordinates.size(); ++i) {
        polygons[i] = decodePolygonCoordinates(coordinates.get(i), fac);
    }/*from ww  w .  ja  v  a2s  .co m*/
    return fac.createMultiPolygon(polygons);
}

From source file:com.github.fge.jsonschema.processors.validation.InstanceValidator.java

@Override
public FullData process(final ProcessingReport report, final FullData input) throws ProcessingException {
    /*//from  ww  w.j  a  v a  2 s. c om
     * We don't want the same validation context to appear twice, see above
     */
    if (!visited.add(FULL_DATA_EQUIVALENCE.wrap(input)))
        throw new ProcessingException(validationLoopMessage(input));

    /*
     * Build a validation context, attach a report to it
     */
    final SchemaContext context = new SchemaContext(input);

    /*
     * Get the full context from the cache. Inject the messages into the
     * main report.
     */
    final ValidatorList fullContext = keywordBuilder.process(report, context);

    if (fullContext == null) {
        final ProcessingMessage message = collectSyntaxErrors(report);
        throw new InvalidSchemaException(message);
    }

    /*
     * Get the calculated context. Build the data.
     */
    final SchemaContext newContext = fullContext.getContext();
    final FullData data = new FullData(newContext.getSchema(), input.getInstance(), input.isDeepCheck());

    /*
     * Validate against all keywords.
     */
    for (final KeywordValidator validator : fullContext)
        validator.validate(this, report, validationMessages, data);

    /*
     * At that point, if the report is a failure, we quit: there is no
     * reason to go any further. Unless the user has asked to continue even
     * in this case.
     */
    if (!(report.isSuccess() || data.isDeepCheck()))
        return input;

    /*
     * Now check whether this is a container node with a size greater than
     * 0. If not, no need to go see the children.
     */
    final JsonNode node = data.getInstance().getNode();
    if (node.size() == 0)
        return input;

    if (node.isArray())
        processArray(report, data);
    else
        processObject(report, data);

    return input;
}

From source file:net.logstash.logback.encoder.LogstashEncoderTest.java

private void assertJsonArray(JsonNode jsonNode, String... expected) {
    String[] values = new String[jsonNode.size()];
    for (int i = 0; i < values.length; i++) {
        values[i] = jsonNode.get(i).asText();
    }/*w ww.  j a v a  2  s.co m*/

    Assert.assertArrayEquals(expected, values);
}

From source file:com.googlecode.batchfb.impl.QueryNodeExtractor.java

/** */
@Override//from w  ww . j a  va2s .  co m
protected JsonNode convert(JsonNode data) {

    if (!(data instanceof ArrayNode))
        throw new IllegalStateException("Expected array node: " + data);

    // If you have an NPE here it means you didn't initialize the Request properly!
    String name = this.request.getName();

    for (int i = 0; i < data.size(); i++) {
        JsonNode candidate = data.get(i);

        if (name.equals(candidate.path("name").textValue()))
            return candidate.get("fql_result_set");
    }

    throw new IllegalStateException("Didn't find query named '" + name + "' in query results");
}

From source file:org.dswarm.graph.gdm.test.GDMResourceTest.java

@Test
public void testResourceTypeNodeUniqueness() throws IOException {

    writeGDMToDBInternal("http://data.slub-dresden.de/resources/1", DEFAULT_GDM_FILE_NAME);
    writeGDMToDBInternal("http://data.slub-dresden.de/resources/2", DEFAULT_GDM_FILE_NAME);

    final String typeQuery = "MATCH (n:TYPE_RESOURCE) RETURN id(n) AS node_id, n.uri AS node_uri;";

    final ObjectMapper objectMapper = Util.getJSONObjectMapper();

    final ObjectNode requestJson = objectMapper.createObjectNode();

    requestJson.put("query", typeQuery);

    final String requestJsonString = objectMapper.writeValueAsString(requestJson);

    final ClientResponse response = cypher().type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, requestJsonString);

    Assert.assertEquals("expected 200", 200, response.getStatus());

    final String body = response.getEntity(String.class);

    final ObjectNode bodyJson = objectMapper.readValue(body, ObjectNode.class);

    Assert.assertNotNull(bodyJson);//from  ww  w.j av a 2s .  c o  m

    final JsonNode dataNode = bodyJson.get("data");

    Assert.assertNotNull(dataNode);
    Assert.assertTrue(dataNode.size() > 0);

    final Map<String, Long> resourceTypeMap = Maps.newHashMap();

    for (final JsonNode entry : dataNode) {

        final String resourceType = entry.get(1).textValue();
        final long nodeId = entry.get(0).longValue();

        if (resourceTypeMap.containsKey(resourceType)) {

            final Long existingNodeId = resourceTypeMap.get(resourceType);

            Assert.assertTrue("resource node map already contains a node for resource type '" + resourceType
                    + "' with the id '" + existingNodeId + "', but found another node with id '" + nodeId
                    + "' for this resource type", false);
        }

        resourceTypeMap.put(resourceType, nodeId);
    }
}