Example usage for com.fasterxml.jackson.databind.node ArrayNode size

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode size.

Prototype

public int size() 

Source Link

Usage

From source file:org.gitana.platform.client.job.JobLogEntry.java

public List<String> getStackTrace() {
    List<String> list = new ArrayList<String>();

    if (has(FIELD_STACKTRACE)) {
        ArrayNode array = getArray(FIELD_STACKTRACE);
        for (int i = 0; i < array.size(); i++) {
            String element = (String) array.get(i).textValue();

            list.add(element);//w ww  . java 2  s  .com
        }
    }

    return list;
}

From source file:org.gitana.platform.client.log.LogEntryImpl.java

@Override
public List<LogThrowable> getLogThrowables() {
    List<LogThrowable> throwables = new ArrayList<LogThrowable>();

    ArrayNode array = getArray(FIELD_THROWABLES);
    for (int i = 0; i < array.size(); i++) {
        ObjectNode object = (ObjectNode) array.get(i);

        throwables.add(new LogThrowable(object));
    }//from w ww .  j  av  a 2  s .  c  om

    return throwables;
}

From source file:com.unboundid.scim2.server.utils.ResourceTrimmer.java

/**
 * Trim attributes of the values in the array node to return.
 *
 * @param arrayNode The array node to return.
 * @param parentPath  The parent path of attributes in the array.
 * @return The trimmed object node ready to return to the client.
 *//*  www .  j a v  a 2s  . c  o  m*/
protected ArrayNode trimArrayNode(final ArrayNode arrayNode, final Path parentPath) {
    ArrayNode arrayToReturn = JsonUtils.getJsonNodeFactory().arrayNode();
    for (JsonNode value : arrayNode) {
        if (value.isArray()) {
            ArrayNode trimmedNode = trimArrayNode((ArrayNode) value, parentPath);
            if (trimmedNode.size() > 0) {
                arrayToReturn.add(trimmedNode);
            }
        } else if (value.isObject()) {
            ObjectNode trimmedNode = trimObjectNode((ObjectNode) value, parentPath);
            if (trimmedNode.size() > 0) {
                arrayToReturn.add(trimmedNode);
            }
        } else {
            arrayToReturn.add(value);
        }
    }
    return arrayToReturn;
}

From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSourceTest.java

@Test
public void testMergeReplaceLiteralWithArrayNode() {
    final JsonNodeMergingSource source = new JsonNodeMergingSource.Builder()
            .addSource(new JsonNodeLiteralSource.Builder().setSource("\"foo\"").build())
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"1\"]").build()).build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    final ArrayNode arrayNode = (ArrayNode) source.getValue().get();
    Assert.assertEquals(1, arrayNode.size());
    Assert.assertEquals("1", arrayNode.get(0).asText());
}

From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSourceTest.java

@Test
public void testMergeReplaceObjectNodeWithArrayNode() {
    final JsonNodeMergingSource source = new JsonNodeMergingSource.Builder()
            .addSource(new JsonNodeLiteralSource.Builder().setSource("{\"a\":\"1\"}").build())
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"1\"]").build()).build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    final ArrayNode arrayNode = (ArrayNode) source.getValue().get();
    Assert.assertEquals(1, arrayNode.size());
    Assert.assertEquals("1", arrayNode.get(0).asText());
}

From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSourceTest.java

@Test
public void testMergeArrayNodeAndArrayNode() {
    final JsonNodeMergingSource source = new JsonNodeMergingSource.Builder()
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"1\"]").build())
            .addSource(new JsonNodeLiteralSource.Builder().setSource("[\"2\"]").build()).build();
    Assert.assertTrue(source.getJsonNode().isPresent());
    final ArrayNode arrayNode = (ArrayNode) source.getValue().get();
    Assert.assertEquals(2, arrayNode.size());
    Assert.assertEquals("1", arrayNode.get(0).asText());
    Assert.assertEquals("2", arrayNode.get(1).asText());
}

From source file:org.opencredo.couchdb.inbound.CouchDbAllDocumentsMessageSource.java

public Message<URI> receive() {
    if (toBeReceived.isEmpty()) {
        URI skipUri = UriComponentsBuilder.fromUri(databaseUri).replaceQueryParam("limit", limit)
                .replaceQueryParam("skip", skip).build().toUri();
        ObjectNode response = couchDbDocumentOperations.readDocument(skipUri, ObjectNode.class);
        ArrayNode rows = (ArrayNode) response.get("rows");
        int size = rows.size();
        Assert.isTrue(size <= limit, "Retrieved more rows than limit");
        for (int i = 0; i < size; i++) {
            JsonNode node = rows.get(i);
            String id = node.get("id").textValue();
            try {
                toBeReceived.add(new URI(baseUri + "/" + id));
                skip++;//from  w  ww  .  j a v  a  2  s  . c  om
            } catch (URISyntaxException e) {
                logger.error("Error creating the URI of document from baseUri and ID", e);
                return null;
            }
        }
    }

    Map<String, String> headers = createHeaderMap(databaseUri, skip, limit);
    return prepareMessage(toBeReceived.poll(), headers);
}

From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTests.java

@Test(expected = PathNotFoundException.class)
public void testExtractArrayPathNotFound() {

    // if the query includes a property that does not exist at all in the data, a PathNotFoundException is thrown
    ArrayNode result = new JsonPathSelector("$.store.cars[*]").call(booksJson);

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

From source file:io.wcm.caravan.pipeline.impl.operators.ExtractOperator.java

@Override
public Subscriber<? super JsonPipelineOutput> call(Subscriber<? super JsonPipelineOutput> subscriber) {
    return new Subscriber<JsonPipelineOutput>() {

        @Override//from ww  w  . j  a  va 2  s .  c o  m
        public void onCompleted() {
            subscriber.onCompleted();
        }

        @Override
        public void onError(Throwable e) {
            Exceptions.throwIfFatal(e);
            subscriber.onError(e);
        }

        @Override
        public void onNext(JsonPipelineOutput output) {
            ArrayNode result = new JsonPathSelector(jsonPath).call(output.getPayload());

            JsonNode extractedPayload = result.size() == 0 ? MissingNode.getInstance() : result.get(0);

            if (isNotBlank(targetProperty)) {
                extractedPayload = JacksonFunctions.wrapInObject(targetProperty, extractedPayload);
            }

            JsonPipelineOutput extractedOutput = output.withPayload(extractedPayload);
            subscriber.onNext(extractedOutput);
        }
    };
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

public static ObjectNode buildSchemaNode(final ObjectMapper objectMapper, final URI schemaUri,
        final SchemaLoader schemaLoader, final Set<URI> addedBaseSchemaUris) {

    final Prototype prototype = schemaLoader.getPrototype(schemaUri);
    if (prototype == null) {
        return null;
    }/*from  ww  w .  j a va  2  s .c o m*/

    final ObjectNode schemaNode = objectMapper.createObjectNode();
    schemaNode.put(PropertyName.localName.name(), prototype.getUniqueName().getLocalName());
    schemaNode.put(PropertyName.title.name(), prototype.getTitle());
    schemaNode.put(PropertyName.uri.name(), schemaUri.toString());
    schemaNode.put(PropertyName.version.name(), prototype.getVersion());

    String titleSlotName = prototype.getTitleSlotName();
    if (StringUtils.isNotBlank(titleSlotName)) {
        schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName);
    } else {
        titleSlotName = getTitleSlotName(schemaUri, schemaLoader);
        if (StringUtils.isNotBlank(titleSlotName)) {
            schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName);
        }
    }

    final Set<String> allSlotNames = prototype.getAllSlotNames();
    if (allSlotNames != null && !allSlotNames.isEmpty()) {
        final ArrayNode propertyNamesNode = objectMapper.createArrayNode();

        for (final String slotName : allSlotNames) {
            final ProtoSlot protoSlot = prototype.getProtoSlot(slotName);
            if (protoSlot instanceof LinkProtoSlot) {
                continue;
            }

            if (protoSlot.getDeclaringSchemaUri().equals(schemaUri)) {
                propertyNamesNode.add(slotName);
            }
        }
        if (propertyNamesNode.size() > 0) {
            schemaNode.put(PropertyName.propertyNames.name(), propertyNamesNode);
        }
    }

    final Set<String> keySlotNames = prototype.getDeclaredKeySlotNames();
    if (keySlotNames != null && !keySlotNames.isEmpty()) {
        final ArrayNode keyPropertyNamesNode = objectMapper.createArrayNode();

        for (final String keySlotName : keySlotNames) {
            keyPropertyNamesNode.add(keySlotName);
        }

        if (keyPropertyNamesNode.size() > 0) {
            schemaNode.put(PropertyName.keyPropertyNames.name(), keyPropertyNamesNode);
        }
    }

    final Set<String> allKeySlotNames = prototype.getAllKeySlotNames();
    final ArrayNode allKeySlotNamesNode = objectMapper.createArrayNode();
    schemaNode.put(PropertyName.allKeySlotNames.name(), allKeySlotNamesNode);

    for (final String keySlotName : allKeySlotNames) {
        allKeySlotNamesNode.add(keySlotName);
    }

    final Set<String> comparablePropertyNames = prototype.getComparableSlotNames();
    if (comparablePropertyNames != null && !comparablePropertyNames.isEmpty()) {
        final ArrayNode comparablePropertyNamesNode = objectMapper.createArrayNode();

        for (final String comparablePropertyName : comparablePropertyNames) {
            comparablePropertyNamesNode.add(comparablePropertyName);
        }

        if (comparablePropertyNamesNode.size() > 0) {
            schemaNode.put(PropertyName.comparablePropertyNames.name(), comparablePropertyNamesNode);
        }
    }

    final Map<URI, LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots();
    if (linkProtoSlots != null && !linkProtoSlots.isEmpty()) {
        final ArrayNode linkNamesNode = objectMapper.createArrayNode();

        for (final LinkProtoSlot linkProtoSlot : linkProtoSlots.values()) {
            if (linkProtoSlot.getDeclaringSchemaUri().equals(schemaUri)) {
                linkNamesNode.add(linkProtoSlot.getName());
            }
        }

        if (linkNamesNode.size() > 0) {
            schemaNode.put(PropertyName.linkNames.name(), linkNamesNode);
        }
    }

    final Set<URI> declaredBaseSchemaUris = prototype.getDeclaredBaseSchemaUris();
    if (declaredBaseSchemaUris != null && !declaredBaseSchemaUris.isEmpty() && addedBaseSchemaUris != null) {

        final ArrayNode baseSchemasNode = objectMapper.createArrayNode();
        for (final URI baseSchemaUri : declaredBaseSchemaUris) {
            if (!addedBaseSchemaUris.contains(baseSchemaUri)) {
                final ObjectNode baseSchemaNode = buildSchemaNode(objectMapper, baseSchemaUri, schemaLoader,
                        addedBaseSchemaUris);
                baseSchemasNode.add(baseSchemaNode);
                addedBaseSchemaUris.add(baseSchemaUri);
            }
        }

        if (baseSchemasNode.size() > 0) {
            schemaNode.put(PropertyName.baseSchemas.name(), baseSchemasNode);
        }
    }

    return schemaNode;
}