List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
@Test public void testDirectoryOnlyMatchingNamePatterns() throws IOException { final File directory = new File( "./target/tmp/filter/JsonNodeDirectorySourceTest/testDirectoryOnlyMatchingNamePatterns"); deleteDirectory(directory);/*from w w w. j a va2 s.c o m*/ Files.createDirectory(directory.toPath()); Files.write(directory.toPath().resolve("foo.json"), "[\"one\"]".getBytes(Charsets.UTF_8)); Files.write(directory.toPath().resolve("bar.txt"), "[\"two\"]".getBytes(Charsets.UTF_8)); final JsonNodeDirectorySource source = new JsonNodeDirectorySource.Builder().setDirectory(directory) .addFileNamePattern(Pattern.compile(".*\\.json")).build(); Assert.assertTrue(source.getJsonNode().isPresent()); Assert.assertTrue(source.getJsonNode().get().isArray()); final ArrayNode arrayNode = (ArrayNode) source.getJsonNode().get(); Assert.assertEquals(1, arrayNode.size()); Assert.assertTrue(arrayNodeContains(arrayNode, "one")); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArrayMultipleObjects() { ArrayNode result = new JsonPathSelector("$.store.book[*]").call(booksJson); assertEquals(4, result.size()); assertEquals("Nigel Rees", result.get(0).get("author").asText()); assertEquals("Evelyn Waugh", result.get(1).get("author").asText()); }
From source file:org.springframework.social.facebook.api.impl.SocialContextTemplate.java
private CountedList<Reference> getSocialContext(String userId, String context, int limit) { URIBuilder uriBuilder = URIBuilder.fromUri(GRAPH_API_URL + userId).queryParam("fields", "context.fields(" + context + ".limit(" + limit + "))"); JsonNode responseNode = rest.getForObject(uriBuilder.build(), JsonNode.class); JsonNode contextNode = responseNode.get("context").get(context); ArrayNode dataNode = (ArrayNode) contextNode.get("data"); ArrayList<Reference> results = new ArrayList<Reference>(dataNode.size()); for (JsonNode itemNode : dataNode) { results.add(new Reference(itemNode.get("id").textValue(), itemNode.get("name").textValue())); }// www . j a va2 s. c o m Integer totalCount = (contextNode.has("summary") && contextNode.get("summary").has("total_count")) ? contextNode.get("summary").get("total_count").intValue() : null; return new CountedList<Reference>(results, totalCount); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArraySingleArray() { // note that this will not give you the array of books directly // to achieve that, use either $.store.book[*] or use the NodeSelector ArrayNode result = new JsonPathSelector("$.store.book").call(booksJson); assertEquals(1, result.size()); ArrayNode books = (ArrayNode) result.get(0); assertEquals(4, books.size());//from www .ja v a2 s . c o m assertEquals("Nigel Rees", books.get(0).get("author").asText()); assertEquals("Evelyn Waugh", books.get(1).get("author").asText()); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArraySingleString() { ArrayNode result = new JsonPathSelector("$.store.bicycle.color").call(booksJson); assertEquals(1, result.size()); assertEquals("red", result.get(0).asText()); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArrayQuery() { // find all books cheaper than 10 ArrayNode result = new JsonPathSelector("$..book[?(@.price<10)]").call(booksJson); assertEquals(2, result.size()); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArrayMultipleStrings() { ArrayNode result = new JsonPathSelector("$.store.book[*].author").call(booksJson); assertEquals(4, result.size()); assertEquals("Nigel Rees", result.get(0).asText()); assertEquals("Evelyn Waugh", result.get(1).asText()); }
From source file:org.gitana.platform.client.team.TeamImpl.java
@Override public List<String> getRoleKeys() { List<String> roleKeys = new ArrayList<String>(); ArrayNode array = getArray(FIELD_ROLE_KEYS); for (int i = 0; i < array.size(); i++) { String roleKey = (String) array.get(i).textValue(); roleKeys.add(roleKey);// w w w . ja v a 2 s . co m } return roleKeys; }
From source file:io.wcm.caravan.pipeline.impl.operators.AssertExistsOperator.java
@Override public Subscriber<? super JsonPipelineOutput> call(Subscriber<? super JsonPipelineOutput> subscriber) { return new Subscriber<JsonPipelineOutput>() { private boolean assertionFailed; @Override//from w w w. j ava 2 s .com public void onCompleted() { // take care not to call #onCompleted if #onError has been called because the assertion failed if (!assertionFailed) { subscriber.onCompleted(); } } @Override public void onError(Throwable e) { Exceptions.throwIfFatal(e); subscriber.onError(e); } @Override public void onNext(JsonPipelineOutput output) { JsonNode jsonResponse = output.getPayload(); // if this #assertExist is chained after an #extract call, the responseNode or its child node can be a MissingNode and we should bail out early if (jsonResponse == null || jsonResponse.isMissingNode() || !jsonResponse.iterator().hasNext() || (jsonResponse.isObject() && jsonResponse.iterator().next().isMissingNode())) { onAssertionFailed(); return; } try { // evalute the JSONPath on the pipeline's response ArrayNode jsonPathResult = new JsonPathSelector(jsonPath).call(jsonResponse); if (jsonPathResult.size() == 0) { onAssertionFailed(); } else { // the responseNode has content at the given JsonPath, so we can continue processing the response subscriber.onNext(output); } } catch (PathNotFoundException p) { onAssertionFailed(); } } public void onAssertionFailed() { assertionFailed = true; this.onError(new JsonPipelineInputException(statusCode, msg)); } }; }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Collects the values for the both arrays have in common * @param array1/*from w w w .j av a2 s .c o m*/ * @param array2 * @return an array which contains all values both arrays have in common */ public ArrayNode intersect(ArrayNode array1, ArrayNode array2) { ArrayNode result = objectMapper.createArrayNode(); for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) { JsonNode node1 = array1.get(i1); for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) { JsonNode node2 = array2.get(i2); if (node1.equals(node2)) { result.add(node2); } } } return result; }