List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:org.springframework.social.facebook.api.impl.FriendTemplate.java
public PagedList<String> getFriendIds(String userId) { URI uri = URIBuilder.fromUri(GraphApi.GRAPH_API_URL + userId + "/friends").queryParam("fields", "id") .build();//w w w . j a va2s. c om JsonNode responseNode = restTemplate.getForObject(uri, JsonNode.class); ArrayNode dataNode = (ArrayNode) responseNode.get("data"); List<String> idList = new ArrayList<String>(dataNode.size()); for (JsonNode entryNode : dataNode) { idList.add(entryNode.get("id").textValue()); } Integer totalCount = responseNode.has("summary") && responseNode.get("summary").has("total_count") ? responseNode.get("summary").get("total_count").asInt() : null; return new PagedList<String>(idList, null, null, totalCount); }
From source file:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java
public void execute(PutAttributesContext ctx) throws Exception { if (ctx.isCreateDomainIfNeeded()) createIfNeeded(ctx);/*from w ww. j av a2s . c o m*/ ArrayNode attributesArray = (ArrayNode) new ObjectMapper().readTree(ctx.getSource()); for (int i = 0; i < attributesArray.size(); i++) { ObjectNode putAttributeNode = (ObjectNode) attributesArray.get(i); putAttribute(ctx, putAttributeNode); } }
From source file:org.springframework.social.vkontakte.api.impl.AbstractVKontakteOperations.java
/** * for responses of VK API 5.0+/*from w w w. j av a2 s .co m*/ * @param response * @param itemClass * @param <T> * @return */ protected <T> VKArray<T> deserializeVK50ItemsResponse(VKGenericResponse response, Class<T> itemClass) { checkForError(response); JsonNode jsonNode = response.getResponse(); JsonNode itemsNode = jsonNode.get("items"); Assert.isTrue(itemsNode.isArray()); int count = jsonNode.get("count").asInt(); ArrayNode items = (ArrayNode) itemsNode; List<T> elements = new ArrayList<T>(); for (int i = 0; i < items.size(); i++) { elements.add(objectMapper.convertValue(items.get(i), itemClass)); } return new VKArray<T>(count, elements); }
From source file:org.walkmod.conf.providers.yml.AbstractYMLConfigurationAction.java
@Override public void execute() throws Exception { JsonNode node = provider.getRootNode(); boolean isMultiModule = node.has("modules"); if (recursive && isMultiModule) { JsonNode aux = node.get("modules"); if (aux.isArray()) { ArrayNode modules = (ArrayNode) aux; int max = modules.size(); for (int i = 0; i < max; i++) { JsonNode module = modules.get(i); if (module.isTextual()) { String moduleDir = module.asText(); try { File auxFile = new File(provider.getFileName()).getCanonicalFile().getParentFile(); YAMLConfigurationProvider child = new YAMLConfigurationProvider( auxFile.getAbsolutePath() + File.separator + moduleDir + File.separator + "walkmod.yml"); child.createConfig(); AbstractYMLConfigurationAction childAction = clone(child, recursive); childAction.execute(); } catch (IOException e) { throw new TransformerException(e); }/*from ww w .jav a 2 s .c o m*/ } } } } else { doAction(node); } }
From source file:org.flowable.rest.dmn.service.api.decision.DmnRuleServiceResourceTest.java
@DmnDeploymentAnnotation(resources = { "org/flowable/rest/dmn/service/api/decision/single-hit.dmn" }) public void testExecutionDecisionSingleResult() throws Exception { // Add decision key ObjectNode requestNode = objectMapper.createObjectNode(); requestNode.put("decisionKey", "decision"); // add input variable ArrayNode variablesNode = objectMapper.createArrayNode(); ObjectNode variableNode1 = objectMapper.createObjectNode(); variableNode1.put("name", "inputVariable1"); variableNode1.put("type", "integer"); variableNode1.put("value", 5); variablesNode.add(variableNode1);/*from w w w.j av a2 s .c om*/ ObjectNode variableNode2 = objectMapper.createObjectNode(); variableNode2.put("name", "inputVariable2"); variableNode2.put("type", "string"); variableNode2.put("value", "test2"); variablesNode.add(variableNode2); requestNode.set("inputVariables", variablesNode); HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + DmnRestUrls.createRelativeResourceUrl(DmnRestUrls.URL_RULE_SERVICE_EXECUTE_SINGLE_RESULT)); httpPost.setEntity(new StringEntity(requestNode.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED); // Check response JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); ArrayNode resultVariables = (ArrayNode) responseNode.get("resultVariables"); assertEquals(1, resultVariables.size()); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArraySingleObject() { ArrayNode result = new JsonPathSelector("$.store.bicycle").call(booksJson); assertEquals(1, result.size()); assertEquals("red", result.get(0).get("color").asText()); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test 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:org.bonitasoft.web.designer.model.contract.databind.ContractDeserializer.java
private void parseNodeContractInput(ArrayNode inputArray, ContractInputContainer rootNodeInput) throws IOException { for (int i = 0; i < inputArray.size(); i++) { JsonNode childNode = inputArray.get(i); Class<?> inputType = inputType(childNode); if (inputType.equals(NodeContractInput.class)) { NodeContractInput nodeContractInput = newNodeContractInput(childNode); rootNodeInput.addInput(nodeContractInput); parseNodeContractInput(childInput(childNode), nodeContractInput); } else {/* w ww . ja va2s.c o m*/ rootNodeInput.addInput(newLeafContractInput(childNode, inputType)); } } }
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
@Test public void testDirectoryAll() throws IOException { final File directory = new File("./target/tmp/filter/JsonNodeDirectorySourceTest/testDirectoryAll"); deleteDirectory(directory);//from w ww. j av a2 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) .build(); Assert.assertTrue(source.getJsonNode().isPresent()); Assert.assertTrue(source.getJsonNode().get().isArray()); final ArrayNode arrayNode = (ArrayNode) source.getJsonNode().get(); Assert.assertEquals(2, arrayNode.size()); Assert.assertTrue(arrayNodeContains(arrayNode, "one")); Assert.assertTrue(arrayNodeContains(arrayNode, "two")); }
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
@Test public void testDirectoryOnlyMatchingNames() throws IOException { final File directory = new File( "./target/tmp/filter/JsonNodeDirectorySourceTest/testDirectoryOnlyMatchingNames"); deleteDirectory(directory);// w ww. j av a2 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) .addFileName("foo.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")); }