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.fge.jsonschema.syntax.checkers.draftv3.ExtendsSyntaxChecker.java

@Override
protected void extraChecks(final ProcessingReport report, final SchemaTree tree) throws ProcessingException {
    final JsonNode node = tree.getNode().get(keyword);
    if (node.isArray() && node.size() == 0)
        report.warn(newMsg(tree, "extendsEmptyArray"));
}

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

@Override
public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) {
    if (instance.size() > itemsCount) {
        final Message.Builder msg = newMsg().setMessage("additional items are not permitted")
                .addInfo("max", itemsCount).addInfo("found", instance.size());
        report.addMessage(msg.build());//  ww  w.j  a  v a 2s  .  c o  m
    }
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.ExtendsSyntaxChecker.java

@Override
protected void extraChecks(final ProcessingReport report, final MessageBundle bundle, final SchemaTree tree)
        throws ProcessingException {
    final JsonNode node = tree.getNode().get(keyword);
    if (node.isArray() && node.size() == 0)
        report.warn(newMsg(tree, bundle, "draftv3.extends.emptyArray"));
}

From source file:com.nebhale.jsonpath.internal.component.DeepWildcardPathComponentTest.java

@Test
public void select() {
    JsonNode result = new DeepWildcardPathComponent(null).select(NODE);

    assertEquals(38, result.size());
}

From source file:com.redhat.lightblue.util.JsonNodeCursor.java

@Override
protected boolean hasChildren(JsonNode node) {
    return node.isContainerNode() && node.size() > 0;
}

From source file:com.infinities.keystone4j.admin.v3.ApiV3ResourceTest.java

@Test
public void testGetVersion() throws JsonParseException, IOException {
    Response response = target("/").path("v3").request().get();
    assertEquals(200, response.getStatus());
    JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class));
    JsonNode versionV3 = node.get("version");
    assertNotNull(versionV3);//from w  w w.  j  a v a  2s  . c  om
    assertEquals("v3.0", versionV3.get("id").asText());
    assertEquals("stable", versionV3.get("status").asText());
    assertEquals("2013-03-06T00:00:00Z", versionV3.get("updated").asText());
    JsonNode links = versionV3.get("links");
    assertEquals(1, links.size());
    JsonNode link = links.get(0);
    assertEquals("self", link.get("rel").asText());
    String url = Config.Instance.getOpt(Config.Type.DEFAULT, "admin_endpoint").asText();
    url = Config.replaceVarWithConf(url) + "v3/";
    assertEquals(url, link.get("href").asText());
    JsonNode medias = versionV3.get("media-types");
    assertEquals(1, medias.size());
    JsonNode media = medias.get(0);
    assertEquals("application/json", media.get("base").asText());
    assertEquals("application/vnd.openstack.identity-v3+json", media.get("type").asText());
}

From source file:com.github.dpsm.android.print.jackson.model.JacksonPrinterSearchResult.java

public JacksonPrinterSearchResult(final ObjectNode objectNode) {
    super(objectNode);

    final JsonNode node = mObjectNode.get("printers");
    printers = new ArrayList<JacksonPrinter>(node.size());
    for (JsonNode child : node) {
        printers.add(new JacksonPrinter((ObjectNode) child));
    }//www.  j  a v  a2  s  .c  om
}

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

@Override
public boolean isCompatibleToSchemaArray(JsonNode schemaArray, AdditionalItemsField additional) {
    int arraySize = schemaArray.size();
    int checkMax = _maxItems < 0 ? arraySize : Math.min(_maxItems, arraySize);
    for (int i = 0; i < checkMax; i++) {
        if (!_schemaMatcher.isCompatibleTo(schemaArray.get(i))) {
            return false;
        }/*  w w  w .  j  a  v a2  s. co  m*/
    }

    // if the maximum is below or equal to the schemas we checked, or additionals aren't restricted this is just fine.
    if (additional.allowsEverything() || (_maxItems >= 0 && _maxItems <= arraySize)) {
        return true;
    }

    // otherwise it doesn't allow any or is a schema that needs to be compatible
    return additional.isSchema() && _schemaMatcher.isCompatibleTo(additional.getSchema());
}

From source file:org.eel.kitchen.jsonschema.syntax.EnumSyntaxChecker.java

@Override
void checkValue(final Message.Builder msg, final List<Message> messages, final JsonNode schema) {
    final JsonNode enumNode = schema.get(keyword);

    if (enumNode.size() == 0) {
        msg.setMessage("an enum array must have at least one element");
        messages.add(msg.build());//from   w ww  . j a va 2  s  .c  o m
        return;
    }

    /*
     * NOTE: we choose NOT to display the culprit element. The (admittedly
     * convoluted) reason is that said element, as per enum rules,
     * may be an arbitrary JSON document -- ie, as large as you can fathom.
     *
     * TODO: we may do with displaying the index in the array, that's better
     * than nothing...
     */
    final Set<JsonNode> values = Sets.newHashSet();

    for (final JsonNode value : enumNode) {
        if (values.add(value))
            continue;
        msg.setMessage("elements in the array are not unique");
        messages.add(msg.build());
        return;
    }

}

From source file:org.hawkular.services.rest.test.MetricsITest.java

@Test(groups = { GROUP }, dependsOnMethods = { "metricsUp" })
@RunAsClient//  w  w  w .j a v a  2s  .  c o  m
public void postGet() throws Exception {

    final String path = metricsPath + "/gauges/" + gaugeId + "/data";

    /* ensure no data points there already */
    testClient.newRequest().path(path).get().assertCode(204);

    final String json = "[{timestamp: " + gaugeTime + ", value: " + gaugeValue + "}]";
    testClient.newRequest().path(path).postJson(json).assertCode(200);

    testClient.newRequest().path(path).get().assertCode(200).assertJson(dataPoints -> {
        Assert.assertTrue(dataPoints.isArray(), "GET " + path + " should return an array");
        Assert.assertEquals(dataPoints.size(), 1, "GET " + path + " returned an array of unexpected size");
        JsonNode dp0 = dataPoints.get(0);
        Assert.assertEquals(dp0.size(), 2, "first data point has an unexpected number of fields");
        Assert.assertEquals(dp0.get("timestamp").asLong(), gaugeTime,
                "first data point has an unexpected timestamp");
        Assert.assertEquals(dp0.get("value").asInt(), gaugeValue, "first data point has an unexpected value");
    });
}