List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:org.activiti.designer.eclipse.navigator.cloudrepo.ProcessModelContentProvider.java
public Object[] getChildren(Object parentElement) { if (parentElement instanceof ActivitiCloudEditorRoot) { if (modelsNode == null) { try { initializeRootElements(); } catch (final ActivitiCloudEditorException e) { String detailMessage = null; if (e.getExceptionNode() != null) { detailMessage = e.getExceptionNode().get("message").asText(); } else { detailMessage = e.getMessage(); }// www . j a v a2s . c o m // creating fake entry ObjectMapper objectMapper = new ObjectMapper(); modelsNode = objectMapper.createObjectNode(); ArrayNode modelArrayNode = objectMapper.createArrayNode(); ((ObjectNode) modelsNode).put("data", modelArrayNode); ObjectNode errorNode = objectMapper.createObjectNode(); modelArrayNode.add(errorNode); errorNode.put("name", "Process models could not be retrieved: " + detailMessage); } } if (modelsNode != null) { ArrayNode modelArrayNode = (ArrayNode) modelsNode.get("data"); Object[] objectArray = new Object[modelArrayNode.size()]; for (int i = 0; i < modelArrayNode.size(); i++) { JsonNode modelNode = modelArrayNode.get(i); objectArray[i] = modelNode; } return objectArray; } else { return EMPTY_ARRAY; } } else { return EMPTY_ARRAY; } }
From source file:org.teavm.flavour.json.test.SerializerTest.java
@Test public void writesArray() { int[] array = { 23, 42 }; JsonNode node = JSONRunner.serialize(array); assertTrue("Root node should be JSON array", node.isArray()); ArrayNode arrayNode = (ArrayNode) node; assertEquals("Length must be 2", 2, arrayNode.size()); JsonNode firstNode = arrayNode.get(0); assertTrue("Item must be numeric", firstNode.isNumber()); assertEquals(23, firstNode.asInt()); }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ArrayConstructionExpressionEvaluator.java
private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) { List<JRJsonNode> result = new ArrayList<>(); Deque<JRJsonNode> stack = new ArrayDeque<>(); JsonNode initialDataNode = jrJsonNode.getDataNode(); if (log.isDebugEnabled()) { log.debug("initial stack population with: " + initialDataNode); }//from w w w .j a va2 s . c o m // populate the stack initially stack.push(jrJsonNode); while (!stack.isEmpty()) { JRJsonNode stackNode = stack.pop(); JsonNode stackDataNode = stackNode.getDataNode(); addChildrenToStack(stackNode, stack); // process the current stack item if (stackDataNode.isArray()) { if (log.isDebugEnabled()) { log.debug("processing stack element: " + stackDataNode); } ArrayNode newNode = getEvaluationContext().getObjectMapper().createArrayNode(); for (Integer idx : expression.getIndexes()) { if (idx >= 0 && idx < stackDataNode.size()) { JRJsonNode nodeAtIndex = stackNode.createChild(stackDataNode.get(idx)); if (applyFilter(nodeAtIndex)) { newNode.add(nodeAtIndex.getDataNode()); } } } if (newNode.size() > 0) { result.add(stackNode.createChild(newNode)); } } } return result; }
From source file:org.gitana.platform.client.node.NodeImpl.java
@Override public List<String> getTranslationEditions() { Response response = getRemote().get(getResourceUri() + "/i18n/editions"); ArrayNode array = (ArrayNode) response.getObjectNode().get("editions"); List<String> editions = new ArrayList<String>(); for (int i = 0; i < array.size(); i++) { editions.add(array.get(i).textValue()); }//w w w .j ava 2s . com return editions; }
From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java
protected List<JSONChild> getChildren(JsonNode jsonNode) { List<JSONChild> children; JsonNode childrenNode = jsonNode.get(CHILD_NODE_HOLDER); if (childrenNode instanceof ObjectNode) { ObjectNode childrenObject = (ObjectNode) childrenNode; children = new ArrayList<>(childrenObject.size()); for (Iterator<?> iterator = childrenObject.fields(); iterator.hasNext();) { String childName = iterator.next().toString(); //it is not possible to have SNS in the object form, so the index will always be 1 children.add(new JSONChild(childName, childrenObject.get(childName), 1)); }/*from w w w . j a v a 2 s . c o m*/ return children; } else { ArrayNode childrenArray = (ArrayNode) childrenNode; children = new ArrayList<>(childrenArray.size()); Map<String, Integer> visitedNames = new HashMap<>(childrenArray.size()); for (int i = 0; i < childrenArray.size(); i++) { JsonNode child = childrenArray.get(i); if (child.size() == 0) { continue; } if (child.size() > 1) { logger.warn( "The child object {0} has more than 1 elements, only the first one will be taken into account", child); } String childName = child.fields().next().toString(); int sns = visitedNames.containsKey(childName) ? visitedNames.get(childName) + 1 : 1; visitedNames.put(childName, sns); children.add(new JSONChild(childName, child.get(childName), sns)); } return children; } }
From source file:org.gitana.platform.client.node.NodeImpl.java
@Override public List<Locale> getTranslationLocales(String edition) { Response response = getRemote().get(getResourceUri() + "/i18n/locales?edition=" + edition); ArrayNode array = (ArrayNode) response.getObjectNode().get("locales"); List<Locale> locales = new ArrayList<Locale>(); for (int i = 0; i < array.size(); i++) { String localeString = array.get(i).textValue(); Locale locale = org.gitana.util.I18NUtil.parseLocale(localeString); locales.add(locale);//from w w w.ja va 2 s . c o m } return locales; }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void addStringToArray() { String value = "bar"; ArrayNode array = new ArrayNode(factory); Assert.assertEquals(0, array.size()); parser.addStringToArray(array, value); Assert.assertEquals(1, array.size()); Assert.assertEquals(value, array.get(0).textValue()); }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void addObjectToArray() { JsonNode value = new TextNode("asdf"); ArrayNode array = new ArrayNode(factory); Assert.assertEquals(0, array.size()); parser.addObjectToArray(array, value); Assert.assertEquals(1, array.size()); Assert.assertEquals(value, array.get(0)); }
From source file:io.wcm.caravan.pipeline.impl.JsonPipelineImpl.java
@Override public JsonPipeline assertExists(String jsonPath, RuntimeException ex) { Observable<JsonNode> assertingSource = Observable.create(subscriber -> { getOutput().subscribe(new Observer<JsonNode>() { private boolean assertionFailed; @Override// w w w. ja va 2 s .c o m public void onNext(JsonNode responseNode) { // if this #assertExist is chained after an #extract call, the responseNode can be null and we should bail out early if (responseNode == null) { this.onError(ex); return; } try { ArrayNode jsonPathResult = new JsonPathSelector(jsonPath).call(responseNode); if (jsonPathResult.size() == 0) { // the JSONpath was valid, but it just didn't match to any result this.onError(ex); } else { // the responseNode has content at the given JsonPath, so we can continue processing processing the response subscriber.onNext(responseNode); } } catch (PathNotFoundException p) { // the JSONpath didn't match the structure of the response this.onError(ex); } } @Override public void onError(Throwable e) { assertionFailed = true; subscriber.onError(e); } @Override public void onCompleted() { if (!assertionFailed) { subscriber.onCompleted(); } } }); }); return cloneWith(assertingSource, null); }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ObjectKeyExpressionEvaluator.java
private List<JRJsonNode> goDown(JRJsonNode jrJsonNode) { if (log.isDebugEnabled()) { log.debug("going " + MemberExpression.DIRECTION.DOWN + " by " + (expression.isWildcard() ? "wildcard" : "key: [" + expression.getObjectKey() + "]") + " on " + jrJsonNode.getDataNode()); }//from w ww. j av a 2s. c om List<JRJsonNode> result = new ArrayList<>(); JsonNode dataNode = jrJsonNode.getDataNode(); // advance into object if (dataNode.isObject()) { // if wildcard => filter and add all its children(the values for each key) to an arrayNode if (expression.isWildcard()) { ArrayNode container = getEvaluationContext().getObjectMapper().createArrayNode(); Iterator<Map.Entry<String, JsonNode>> it = dataNode.fields(); while (it.hasNext()) { JsonNode current = it.next().getValue(); if (applyFilter(jrJsonNode.createChild(current))) { container.add(current); } } if (container.size() > 0) { result.add(jrJsonNode.createChild(container)); } } // else go down and filter else { JRJsonNode deeperNode = goDeeperIntoObjectNode(jrJsonNode, isCalledFromFilter); if (deeperNode != null) { result.add(deeperNode); } } } // advance into array // when called from filter => keep the array containment else if (dataNode.isArray()) { if (expression.isWildcard()) { result = filterArrayNode(jrJsonNode, (ArrayNode) dataNode, null, isCalledFromFilter); } else { result = filterArrayNode(jrJsonNode, (ArrayNode) dataNode, expression.getObjectKey(), isCalledFromFilter); } } return result; }