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:org.envirocar.server.rest.decoding.json.SensorDecoder.java

private Object parseArrayNode(JsonNode value) {
    List<Object> list = Lists.newArrayListWithExpectedSize(value.size());
    for (int i = 0; i < value.size(); ++i) {
        list.add(parseNode(value.get(i)));
    }//  w ww .j  a  v a  2 s  . c  om
    return list;
}

From source file:org.n52.iceland.config.json.JsonAdminUserDao.java

@Override
public Set<AdministratorUser> getAdminUsers() {
    Set<AdministratorUser> users;
    configuration().readLock().lock();/*w  w  w.  j ava 2  s.c o  m*/
    try {
        JsonNode node = getConfiguration().path(JsonConstants.USERS);
        users = new HashSet<>(node.size());
        node.fieldNames().forEachRemaining(
                name -> users.add(new JsonAdministratorUser(name, node.path(name).asText(null))));
        return users;
    } finally {
        configuration().readLock().unlock();
    }

}

From source file:com.github.fge.jsonschema.walk.collectors.helpers.SchemaOrSchemaArrayPointerCollector.java

@Override
public void collect(final Collection<JsonPointer> pointers, final SchemaTree tree) {
    final JsonNode node = getNode(tree);
    if (node.isObject()) {
        pointers.add(basePointer);/*from  ww  w .  ja v a2 s.  co  m*/
        return;
    }
    final int size = node.size();
    for (int index = 0; index < size; index++)
        pointers.add(basePointer.append(index));
}

From source file:vk.model.VKApiChat.java

/**
 * Fills a Chat instance from JsonNode./*from  ww  w  .  j av a2s  .c  o  m*/
 */
public VKApiChat parse(JsonNode source) {
    id = source.get("id").asInt();
    type = source.get("type").asText();
    title = source.get("title").asText();
    admin_id = source.get("admin_id").asInt();
    JsonNode users = source.get("users");
    if (users != null) {
        this.users = new int[users.size()];
        for (int i = 0; i < this.users.length; i++) {
            this.users[i] = users.get(i).asInt();
        }
    }
    return this;
}

From source file:com.infinities.keystone4j.admin.AdminVersionApiResourceTest.java

@Test
public void testGetVersions() throws JsonParseException, IOException {
    Response response = target("/").request().get();
    assertEquals(300, response.getStatus());
    JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class));
    JsonNode versions = node.get("versions");
    assertNotNull(versions);// w ww  . j  av a2  s  .  c o m
    JsonNode values = versions.get("values");
    assertEquals(2, values.size());
    JsonNode versionV2 = values.get(0);
    assertNotNull(versionV2);
    assertEquals("v2.0", versionV2.get("id").asText());
    assertEquals("stable", versionV2.get("status").asText());
    assertEquals("2014-04-17T00:00:00Z", versionV2.get("updated").asText());
    JsonNode linksV2 = versionV2.get("links");
    assertEquals(3, linksV2.size());
    JsonNode linkV2_0 = linksV2.get(0);
    assertEquals("self", linkV2_0.get("rel").asText());
    String url = Config.Instance.getOpt(Config.Type.DEFAULT, "admin_endpoint").asText();
    url = Config.replaceVarWithConf(url) + "v2.0/";
    assertEquals(url, linkV2_0.get("href").asText());
    JsonNode linkV2_1 = linksV2.get(1);
    assertEquals("describeby", linkV2_1.get("rel").asText());
    assertEquals("text/html", linkV2_1.get("type").asText());
    assertEquals("http://docs.openstack.org/api/openstack-identity-service/v2.0/content/",
            linkV2_1.get("href").asText());
    JsonNode linkV2_2 = linksV2.get(2);
    assertEquals("describeby", linkV2_2.get("rel").asText());
    assertEquals("application/pdf", linkV2_2.get("type").asText());
    assertEquals("http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf",
            linkV2_2.get("href").asText());
    JsonNode mediasV2 = versionV2.get("media-types");
    assertEquals(1, mediasV2.size());
    JsonNode mediaV2 = mediasV2.get(0);
    assertEquals("application/json", mediaV2.get("base").asText());
    assertEquals("application/vnd.openstack.identity-v2.0+json", mediaV2.get("type").asText());

    JsonNode versionV3 = values.get(1);
    assertNotNull(versionV3);
    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());
    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:edu.berkeley.ground.postgres.dao.usage.PostgresLineageGraphVersionDao.java

@Override
public LineageGraphVersion retrieveFromDatabase(long id) throws GroundException {
    String sql = String.format(SqlConstants.SELECT_STAR_BY_ID, "lineage_graph_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   ww w . j  a v  a2s  .  c  o  m

    LineageGraphVersion lineageGraphVersion = Json.fromJson(json.get(0), LineageGraphVersion.class);

    List<Long> edgeIds = new ArrayList<>();
    sql = String.format(SqlConstants.SELECT_LINEAGE_GRAPH_VERSION_EDGES, id);

    JsonNode edgeJson = Json.parse(PostgresUtils.executeQueryToJson(dbSource, sql));
    for (JsonNode edge : edgeJson) {
        edgeIds.add(edge.get("lineageEdgeVersionId").asLong());
    }

    RichVersion richVersion = super.retrieveFromDatabase(id);
    return new LineageGraphVersion(id, richVersion.getTags(), richVersion.getStructureVersionId(),
            richVersion.getReference(), richVersion.getParameters(), lineageGraphVersion.getLineageGraphId(),
            edgeIds);
}

From source file:org.thingsplode.synapse.serializers.jackson.adapters.ParameterWrapperDeserializer.java

@Override
public ParameterWrapper deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    JsonNode node = jp.readValueAsTree();
    if (node != null && node.size() > 0 && node.isContainerNode()) {
        ParameterWrapper pw = ParameterWrapper.create();
        ArrayNode paramsNode = (ArrayNode) node.get("params");
        Iterator<JsonNode> elemIterator = paramsNode.elements();
        while (elemIterator.hasNext()) {
            JsonNode currentNode = elemIterator.next();
            if (currentNode.getNodeType() == JsonNodeType.OBJECT) {
                try {
                    String paramid = ((ObjectNode) currentNode).get("paramid").asText();
                    String typeName = ((ObjectNode) currentNode).get("type").asText();
                    Class paramType = null;
                    if (null != typeName)
                        switch (typeName) {
                        case "long":
                            paramType = Long.TYPE;
                            break;
                        case "byte":
                            paramType = Byte.TYPE;
                            break;
                        case "short":
                            paramType = Short.TYPE;
                            break;
                        case "int":
                            paramType = Integer.TYPE;
                            break;
                        case "float":
                            paramType = Float.TYPE;
                            break;
                        case "double":
                            paramType = Double.TYPE;
                            break;
                        case "boolean":
                            paramType = Boolean.TYPE;
                            break;
                        case "char":
                            paramType = Character.TYPE;
                            break;
                        default:
                            paramType = Class.forName(typeName);
                            break;
                        }/* ww  w .  j  a  v  a2 s  .c o  m*/
                    Object parameterObject = jp.getCodec().treeToValue(currentNode.get("value"), paramType);
                    pw.add(paramid, paramType, parameterObject);
                } catch (ClassNotFoundException ex) {
                    throw new JsonParseException(jp, ex.getMessage());
                }
            }
        }
        return pw;
    } else {
        return null;
    }
}

From source file:org.jboss.pnc.buildagent.server.TestGetRunningProcesses.java

@Test
public void getRunningProcesses() throws Exception {
    String terminalUrl = "http://" + HOST + ":" + PORT;

    HttpURLConnection connection = retrieveProcessList();
    Assert.assertEquals(connection.getResponseMessage(), 200, connection.getResponseCode());

    JsonNode node = readResponse(connection);
    Assert.assertEquals(0, node.size());

    String context = this.getClass().getName() + ".getRunningProcesses";

    ObjectWrapper<Boolean> resultReceived = new ObjectWrapper<>(false);
    Consumer<TaskStatusUpdateEvent> onStatusUpdate = (statusUpdateEvent) -> {
        if (statusUpdateEvent.getNewStatus().equals(Status.RUNNING)) {
            try {
                HttpURLConnection afterExecution = retrieveProcessList();
                Assert.assertEquals(afterExecution.getResponseMessage(), 200, afterExecution.getResponseCode());
                JsonNode nodeAfterExecution = readResponse(afterExecution);
                Assert.assertEquals(1, nodeAfterExecution.size());
                resultReceived.set(true);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }/*  ww w.  ja va 2  s. c  o m*/
        }
    };

    BuildAgentClient buildAgentClient = new BuildAgentClient(terminalUrl, Optional.empty(), onStatusUpdate,
            context);
    buildAgentClient.executeCommand(TEST_COMMAND);

    Supplier<Boolean> evaluationSupplier = () -> resultReceived.get();
    Wait.forCondition(evaluationSupplier, 10, ChronoUnit.SECONDS,
            "Client was not connected within given timeout.");
    buildAgentClient.close();
}

From source file:com.redhat.smonkey.Monkey.java

private JsonNode attemptGenerateValue(JsonNode templateNode) {
    String fname = null;//from  w  w  w.ja v a 2  s  .c om
    if (templateNode.size() == 1) {
        fname = templateNode.fieldNames().next();
    } else if (!templateNode.isContainerNode()) {
        fname = templateNode.asText();
    }
    // Check if this is an escaped name
    if (fname != null && !fname.startsWith("\\")) {
        JsonNode dataNode = templateNode.get(fname);
        if (dataNode == null)
            dataNode = templateNode;
        JsonNode value = generateValue(fname, dataNode);
        if (value != null)
            return value;
    }
    return null;
}

From source file:org.jboss.aerogear.sync.jsonmergepatch.JsonMapperTest.java

@Test
public void patchMessageToJson() {
    final String documentId = "1234";
    final String clientId = "client1";
    final PatchMessage<JsonMergePatchEdit> patchMessage = patchMessage(documentId, clientId,
            newJsonMergePatchEdit("Fletch"));

    final String json = JsonMapper.toJson(patchMessage);
    final JsonNode jsonNode = JsonMapper.asJsonNode(json);
    assertThat(jsonNode.get("msgType").asText(), equalTo("patch"));
    assertThat(jsonNode.get("id").asText(), equalTo(documentId));
    assertThat(jsonNode.get("clientId").asText(), equalTo(clientId));
    final JsonNode editsNode = jsonNode.get("edits");
    assertThat(editsNode.isArray(), is(true));
    assertThat(editsNode.size(), is(1));
    final JsonNode edit = editsNode.iterator().next();
    assertThat(edit.get("serverVersion").asText(), equalTo("0"));
    assertThat(edit.get("clientVersion").asText(), equalTo("0"));
    final JsonNode diffs = edit.get("diffs");
    assertThat(diffs.get("name").asText(), equalTo("Fletch"));
}