List of usage examples for com.fasterxml.jackson.databind JsonNode iterator
public final Iterator<JsonNode> iterator()
From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java
/** Recursive function to pull out potentially nested properties * @param property//from ww w. j a va 2 s . c o m * @return */ protected static Either<Object, Object[]> denestProperties(final JsonNode property) { if (property.isArray()) { // (Arrays of objects (except length 1) are currently discarded here, no support for cardinality, see above) if (1 == property.size()) { // (this is what all the existing properties look like after conversion to graphson) return denestProperties(property.get(0)); } else { return Either.right(Optionals.streamOf(property.iterator(), false).map(j -> jsonNodeToObject(j)) .filter(j -> null != j).toArray()); } } else if (property.isObject()) { return denestProperties(property.get(GraphAnnotationBean.value)); } else { return Either.left(jsonNodeToObject(property)); } }
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 a v a 2 s.c om*/ 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:org.agorava.facebook.impl.FeedServiceImpl.java
private <T> List<T> deserializeList(JsonNode jsonNode, String postType, Class<T> type) { JsonNode dataNode = jsonNode.get("data"); List<T> posts = new ArrayList<T>(); for (Iterator<JsonNode> iterator = dataNode.iterator(); iterator.hasNext();) { posts.add(deserializePost(postType, type, (ObjectNode) iterator.next())); }//from w ww.j a v a 2 s . c o m return posts; }
From source file:org.springframework.social.facebook.api.impl.FeedTemplate.java
private <T> PagedList<T> deserializeList(JsonNode jsonNode, String postType, Class<T> type) { JsonNode dataNode = jsonNode.get("data"); List<T> posts = new ArrayList<T>(); for (Iterator<JsonNode> iterator = dataNode.iterator(); iterator.hasNext();) { posts.add(deserializePost(postType, type, (ObjectNode) iterator.next())); }//from ww w . j a v a 2 s . c om if (jsonNode.has("paging")) { JsonNode pagingNode = jsonNode.get("paging"); PagingParameters previousPage = getPagedListParameters(pagingNode, "previous"); PagingParameters nextPage = getPagedListParameters(pagingNode, "next"); return new PagedList<T>(posts, previousPage, nextPage); } return new PagedList<T>(posts, null, null); }
From source file:org.activiti.rest.service.api.history.HistoricVariableInstanceCollectionResourceTest.java
protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException { // Do the actual call CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response);/*from w w w. j a va2 s .c o m*/ assertEquals(numberOfResultsExpected, dataNode.size()); // Check presence of ID's if (variableName != null) { boolean variableFound = false; Iterator<JsonNode> it = dataNode.iterator(); while (it.hasNext()) { JsonNode dataElementNode = it.next(); JsonNode variableNode = dataElementNode.get("variable"); String name = variableNode.get("name").textValue(); if (variableName.equals(name)) { variableFound = true; if (variableValue instanceof Boolean) { assertTrue("Variable value is not equal", variableNode.get("value").asBoolean() == (Boolean) variableValue); } else if (variableValue instanceof Integer) { assertTrue("Variable value is not equal", variableNode.get("value").asInt() == (Integer) variableValue); } else { assertTrue("Variable value is not equal", variableNode.get("value").asText().equals((String) variableValue)); } } } assertTrue("Variable " + variableName + " is missing", variableFound); } }
From source file:org.flowable.rest.service.api.history.HistoricVariableInstanceCollectionResourceTest.java
protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException { // Do the actual call CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response);/*from ww w . jav a2s . c o m*/ assertEquals(numberOfResultsExpected, dataNode.size()); // Check presence of ID's if (variableName != null) { boolean variableFound = false; Iterator<JsonNode> it = dataNode.iterator(); while (it.hasNext()) { JsonNode dataElementNode = it.next(); JsonNode variableNode = dataElementNode.get("variable"); String name = variableNode.get("name").textValue(); if (variableName.equals(name)) { variableFound = true; if (variableValue instanceof Boolean) { assertTrue("Variable value is not equal", variableNode.get("value").asBoolean() == (Boolean) variableValue); } else if (variableValue instanceof Integer) { assertEquals("Variable value is not equal", variableNode.get("value").asInt(), (int) (Integer) variableValue); } else { assertEquals("Variable value is not equal", variableNode.get("value").asText(), (String) variableValue); } } } assertTrue("Variable " + variableName + " is missing", variableFound); } }
From source file:org.activiti.rest.service.api.history.HistoricVariableInstanceQueryResourceTest.java
protected void assertResultsPresentInDataResponse(String url, ObjectNode body, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException { // Do the actual call HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url); httpPost.setEntity(new StringEntity(body.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response);//from w w w.java2 s .c o m assertEquals(numberOfResultsExpected, dataNode.size()); // Check presence of ID's if (variableName != null) { boolean variableFound = false; Iterator<JsonNode> it = dataNode.iterator(); while (it.hasNext()) { JsonNode dataElementNode = it.next(); JsonNode variableNode = dataElementNode.get("variable"); String name = variableNode.get("name").textValue(); if (variableName.equals(name)) { variableFound = true; if (variableValue instanceof Boolean) { assertTrue("Variable value is not equal", variableNode.get("value").asBoolean() == (Boolean) variableValue); } else if (variableValue instanceof Integer) { assertTrue("Variable value is not equal", variableNode.get("value").asInt() == (Integer) variableValue); } else { assertTrue("Variable value is not equal", variableNode.get("value").asText().equals((String) variableValue)); } } } assertTrue("Variable " + variableName + " is missing", variableFound); } }
From source file:org.flowable.rest.service.api.history.HistoricVariableInstanceQueryResourceTest.java
protected void assertResultsPresentInDataResponse(String url, ObjectNode body, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException { // Do the actual call HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url); httpPost.setEntity(new StringEntity(body.toString())); CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK); // Check status and size JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data"); closeResponse(response);//from w w w. j a v a 2s .c om assertEquals(numberOfResultsExpected, dataNode.size()); // Check presence of ID's if (variableName != null) { boolean variableFound = false; Iterator<JsonNode> it = dataNode.iterator(); while (it.hasNext()) { JsonNode dataElementNode = it.next(); JsonNode variableNode = dataElementNode.get("variable"); String name = variableNode.get("name").textValue(); if (variableName.equals(name)) { variableFound = true; if (variableValue instanceof Boolean) { assertTrue("Variable value is not equal", variableNode.get("value").asBoolean() == (Boolean) variableValue); } else if (variableValue instanceof Integer) { assertEquals("Variable value is not equal", variableNode.get("value").asInt(), (int) (Integer) variableValue); } else { assertEquals("Variable value is not equal", variableNode.get("value").asText(), (String) variableValue); } } } assertTrue("Variable " + variableName + " is missing", variableFound); } }