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.core.keyword.syntax.checkers.draftv3.DraftV3DependenciesSyntaxChecker.java

@Override
protected void checkDependency(final ProcessingReport report, final MessageBundle bundle, final String name,
        final SchemaTree tree) throws ProcessingException {
    final JsonNode node = getNode(tree).get(name);
    NodeType type;//from  www  . j  a  va2 s .  c o m

    type = NodeType.getNodeType(node);

    if (type == NodeType.STRING)
        return;

    if (type != NodeType.ARRAY) {
        report.error(
                newMsg(tree, bundle, "common.dependencies.value.incorrectType").putArgument("property", name)
                        .putArgument("expected", dependencyTypes).putArgument("found", type));
        return;
    }

    final int size = node.size();

    /*
     * Yep, in draft v3, nothing prevents a dependency array from being
     * empty! This is stupid, so at least warn the user.
     */
    if (size == 0) {
        report.warn(newMsg(tree, bundle, "common.array.empty").put("property", name));
        return;
    }

    final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet();

    JsonNode element;
    boolean uniqueElements = true;

    for (int index = 0; index < size; index++) {
        element = node.get(index);
        type = NodeType.getNodeType(element);
        uniqueElements = set.add(EQUIVALENCE.wrap(element));
        if (type == NodeType.STRING)
            continue;
        report.error(newMsg(tree, bundle, "common.array.element.incorrectType").put("property", name)
                .putArgument("index", index).putArgument("expected", EnumSet.of(NodeType.STRING))
                .putArgument("found", type));
    }

    /*
     * Similarly, there is nothing preventing duplicates. Equally stupid,
     * so warn the user.
     */
    if (!uniqueElements)
        report.warn(newMsg(tree, bundle, "common.array.duplicateElements").put("property", name));
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * test string methods.//from  www  .j a  va  2  s  . c om
 * @throws Exception error
 */
@Test
public void testStringPatchOps() throws Exception {
    PatchOperation patchOp = PatchOperation.addStringValues("path1", Lists.newArrayList("value1", "value2"));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    JsonNode jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).textValue(), "value1");
    Assert.assertEquals(jsonNode.get(1).textValue(), "value2");
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.addStringValues(Path.fromString("path1"), Lists.newArrayList("value1", "value2"));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).textValue(), "value1");
    Assert.assertEquals(jsonNode.get(1).textValue(), "value2");
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace("path1", "value1");
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(String.class), "value1");
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace(Path.fromString("path1"), "value1");
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(String.class), "value1");
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * test double methods./*  w ww .j  av  a2s. c o m*/
 * @throws Exception error
 */
@Test
public void testDoublePatchOps() throws Exception {
    PatchOperation patchOp = PatchOperation.addDoubleValues("path1", Lists.newArrayList(1.1, 1.2));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    JsonNode jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).doubleValue(), 1.1, 0.01);
    Assert.assertEquals(jsonNode.get(1).doubleValue(), 1.2, 0.01);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.addDoubleValues(Path.fromString("path1"), Lists.newArrayList(2.1, 2.2));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).doubleValue(), 2.1, 0.01);
    Assert.assertEquals(jsonNode.get(1).doubleValue(), 2.2, 0.01);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace("path1", 734.2);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Double.class), 734.2, 0.01);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace(Path.fromString("path1"), 0.3);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Double.class), 0.3, 0.01);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * test integer methods.//from  ww  w .j a v a  2 s .co m
 * @throws Exception error
 */
@Test
public void testIntegerPatchOps() throws Exception {
    PatchOperation patchOp = PatchOperation.addIntegerValues("path1", Lists.newArrayList(1, 2));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    JsonNode jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).intValue(), 1);
    Assert.assertEquals(jsonNode.get(1).intValue(), 2);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.addIntegerValues(Path.fromString("path1"), Lists.newArrayList(3, 4));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).intValue(), 3);
    Assert.assertEquals(jsonNode.get(1).intValue(), 4);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace("path1", 5);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Integer.class).intValue(), 5);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace(Path.fromString("path1"), 7);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Integer.class).intValue(), 7);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * test long methods.//  w ww  .  j ava 2  s  .c  o  m
 * @throws Exception error
 */
@Test
public void testLongPatchOps() throws Exception {
    PatchOperation patchOp = PatchOperation.addLongValues("path1", Lists.newArrayList(1L, 2L));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    JsonNode jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).longValue(), 1);
    Assert.assertEquals(jsonNode.get(1).longValue(), 2);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.addIntegerValues(Path.fromString("path1"), Lists.newArrayList(3, 4));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).longValue(), 3);
    Assert.assertEquals(jsonNode.get(1).longValue(), 4);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace("path1", 5L);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Long.class).longValue(), 5L);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace(Path.fromString("path1"), 7L);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Long.class).longValue(), 7L);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * test boolean methods./*from w w  w .  j a v  a 2 s . co  m*/
 * @throws Exception error
 */
@Test
public void testBooleanPatchOps() throws Exception {
    PatchOperation patchOp = PatchOperation.addBooleanValues("path1",
            Lists.newArrayList(Boolean.TRUE, Boolean.FALSE));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    JsonNode jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).booleanValue(), Boolean.TRUE.booleanValue());
    Assert.assertEquals(jsonNode.get(1).booleanValue(), Boolean.FALSE.booleanValue());
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.addBooleanValues(Path.fromString("path1"),
            Lists.newArrayList(Boolean.FALSE, Boolean.TRUE));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).booleanValue(), Boolean.FALSE.booleanValue());
    Assert.assertEquals(jsonNode.get(1).booleanValue(), Boolean.TRUE.booleanValue());
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace(Path.fromString("path1"), Boolean.TRUE);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Boolean.class), Boolean.TRUE);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    patchOp = PatchOperation.replace(Path.fromString("path1"), Boolean.FALSE);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(Boolean.class), Boolean.FALSE);
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));
}

From source file:com.unboundid.scim2.common.PatchOpTestCase.java

/**
 * test URI methods.//from  ww  w .j  a v  a  2 s .  c  o  m
 * @throws Exception error
 */
@Test
public void testURIPatchOps() throws Exception {
    URI uri1 = new URI("http://localhost:8080/apps/app1");
    URI uri2 = new URI("Users/1dd6d752-1744-47e5-a4a8-5f5670aa8905");
    PatchOperation patchOp = PatchOperation.addURIValues("path1", Lists.newArrayList(uri1, uri2));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    JsonNode jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).textValue(), uri1.toString());
    Assert.assertEquals(jsonNode.get(1).textValue(), uri2.toString());
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    URI uri3 = new URI("http://localhost:8080/apps/app2");
    URI uri4 = new URI("Users/1dd6d752-1744-47e5-a4a8-5f5670aa8998");
    patchOp = PatchOperation.addURIValues(Path.fromString("path1"), Lists.newArrayList(uri3, uri4));
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD);
    jsonNode = patchOp.getJsonNode();
    Assert.assertTrue(jsonNode.isArray());
    Assert.assertEquals(jsonNode.size(), 2);
    Assert.assertEquals(jsonNode.get(0).textValue(), uri3.toString());
    Assert.assertEquals(jsonNode.get(1).textValue(), uri4.toString());
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    URI uri5 = new URI("http://localhost:8080/apps/app3");
    patchOp = PatchOperation.replace("path1", uri5);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(String.class), uri5.toString());
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));

    URI uri6 = new URI("http://localhost:8080/apps/app4");
    patchOp = PatchOperation.replace(Path.fromString("path1"), uri6);
    Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE);
    Assert.assertEquals(patchOp.getValue(String.class), uri6.toString());
    Assert.assertEquals(patchOp.getPath(), Path.fromString("path1"));
}

From source file:com.servioticy.api.commons.data.SO.java

/**
 * @return true if the action exists in the SO
 *///ww  w .  jav  a 2s . c o m

public boolean checkActuation(String actuationName) {

    JsonNode actions = soRoot.path("actions");
    if (actions == null) {
        //System.out.println("actions is null");
        return false;
    }
    for (int i = 0; i < actions.size(); i++) {
        //System.out.println(i+": "+actions.get(i).path("name").asText());
        if (actions.get(i).path("name").asText().equalsIgnoreCase(actuationName))
            return true;
    }

    return false;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.TestDispatchLayerParsing.java

@Test
public void retries() throws Exception {
    Processor retries = processors.getByName("retries");
    Configuration config = scufl2Tools.configurationFor(retries, profile);
    JsonNode retry = config.getJsonAsObjectNode().get(RETRY);

    assertEquals(3, retry.get("maxRetries").intValue());
    // The remaining properties are at default and should NOT be present
    //        assertEquals(1000, retry.get("initialDelay").intValue());
    //        assertEquals(5000, retry.get("maxDelay").intValue());
    //        assertEquals(1.0, retry.get("backoffFactor").doubleValue(), 0.01);        
    assertEquals(1, retry.size());
}

From source file:com.infinities.keystone4j.intergrated.v3.Keystone4jV3IT.java

private void listUserInGroup(String newUserId, String newGroupId) throws JsonProcessingException, IOException {
    Response response = target("/v3/groups").path(newGroupId).path("users").register(JacksonFeature.class)
            .register(ObjectMapperResolver.class).request().header("X-Auth-Token", getAdminToken()).get();
    assertEquals(200, response.getStatus());
    JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class));
    JsonNode usersJ = node.get("users");
    assertEquals(1, usersJ.size());
    JsonNode userJ = usersJ.get(0);//from ww  w.j a va 2  s.c om
    assertEquals(newUserId, userJ.get("id").asText());
}