Java Code Examples for com.fasterxml.jackson.databind.node.ArrayNode#iterator()
The following examples show how to use
com.fasterxml.jackson.databind.node.ArrayNode#iterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyUtil.java From streams with Apache License 2.0 | 6 votes |
/** * clean an array. * @param content ArrayNode * @return cleaned ArrayNode */ private static ArrayNode cleanArray(ArrayNode content) { if( content.size() == 0) return null; Iterator<JsonNode> items = content.iterator(); for ( ; items.hasNext(); ) { JsonNode item = items.next(); if( item == null ) items.remove(); if( item.getNodeType().equals(JsonNodeType.OBJECT)) { if( item.size() == 0 ) items.remove(); } if( item.getNodeType().equals(JsonNodeType.ARRAY)) { if( item.size() == 0 ) items.remove(); } } if( content.size() == 0) return null; else return content; }
Example 2
Source File: VariableContainsExpressionFunction.java From flowable-engine with Apache License 2.0 | 6 votes |
public static boolean arrayNodeContains(ArrayNode arrayNode, Object value) { Iterator<JsonNode> iterator = arrayNode.iterator(); while (iterator.hasNext()) { JsonNode jsonNode = iterator.next(); if (value == null && jsonNode.isNull()) { return true; } else if (value != null) { if (value instanceof String && jsonNode.isTextual() && StringUtils.equals(jsonNode.asText(), (String) value)) { return true; } else if (value instanceof Number && jsonNode.isLong() && jsonNode.longValue() == ((Number) value).longValue()) { return true; } else if (value instanceof Number && jsonNode.isDouble() && jsonNode.doubleValue() == ((Number) value).doubleValue()) { return true; } else if (value instanceof Number && jsonNode.isInt() && jsonNode.intValue() == ((Number) value).intValue()) { return true; } else if (value instanceof Boolean && jsonNode.isBoolean() && jsonNode.booleanValue() == ((Boolean) value).booleanValue()) { return true; } } } return false; }
Example 3
Source File: AbstractJSONDecoder.java From arctic-sea with Apache License 2.0 | 6 votes |
protected PT_FreeText parseFreeText(JsonNode n) { LocalisedCharacterString localisedCharacterString = new LocalisedCharacterString(""); if (n.isArray()) { ArrayNode arrayNode = (ArrayNode) n; Iterator<JsonNode> it = arrayNode.iterator(); while (it.hasNext()) { final JsonNode next = it.next(); checkAndAddTextAndLanguage(next, localisedCharacterString); } } else if (n.isTextual()) { localisedCharacterString.setValue(n.asText()); } else if (n.isObject()) { checkAndAddTextAndLanguage(n, localisedCharacterString); } return new PT_FreeText().addTextGroup(localisedCharacterString); }
Example 4
Source File: GraphLabelsAndDecoratorsIOProviderV0.java From constellation with Apache License 2.0 | 6 votes |
private List<GraphLabelV0> getLabels(final JsonNode jnode, final String position) { List<GraphLabelV0> labelList = new ArrayList<>(); if (jnode.has(position)) { final ArrayNode labelsNode = (ArrayNode) jnode.get(position); final Iterator<JsonNode> it = labelsNode.iterator(); while (it.hasNext()) { final JsonNode lnode = it.next(); final String attr = lnode.get(GraphLabelsAndDecoratorsV0.FIELD_ATTR).textValue(); final String color = lnode.get(GraphLabelsAndDecoratorsV0.FIELD_COLOR).textValue(); final float radius = lnode.has(GraphLabelsAndDecoratorsV0.FIELD_RADIUS) ? (float) lnode.get(GraphLabelsAndDecoratorsV0.FIELD_RADIUS).asDouble() : 1f; final GraphLabelV0 label = new GraphLabelV0(attr, ConstellationColor.getColorValue(color), radius); labelList.add(label); } } return labelList; }
Example 5
Source File: CmmnModelJsonConverterUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
protected static void internalGetCmmnChildShapePropertyValues(JsonNode editorJsonNode, String propertyName, List<String> allowedStencilTypes, List<JsonLookupResult> result) { JsonNode childShapesNode = editorJsonNode.get("childShapes"); if (childShapesNode != null && childShapesNode.isArray()) { ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode; Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator(); while (childShapeNodeIterator.hasNext()) { JsonNode childShapeNode = childShapeNodeIterator.next(); String childShapeNodeStencilId = CmmnJsonConverterUtil.getStencilId(childShapeNode); boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId); if (readPropertiesNode) { // Properties JsonNode properties = childShapeNode.get("properties"); if (properties != null && properties.has(propertyName)) { JsonNode nameNode = properties.get("name"); JsonNode propertyNode = properties.get(propertyName); result.add(new JsonLookupResult(CmmnJsonConverterUtil.getElementId(childShapeNode), nameNode != null ? nameNode.asText() : null, propertyNode)); } } // Potential nested child shapes if (childShapeNode.has("childShapes")) { internalGetCmmnChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result); } } } }
Example 6
Source File: RemoveModulesYMLAction.java From walkmod-core with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void doAction(JsonNode node) throws Exception { if (node.has("modules")) { JsonNode aux = node.get("modules"); ObjectMapper mapper = provider.getObjectMapper(); if (aux.isArray()) { ArrayNode modulesList = (ArrayNode) node.get("modules"); Iterator<JsonNode> it = modulesList.iterator(); ArrayNode newModulesList = new ArrayNode(mapper.getNodeFactory()); while (it.hasNext()) { JsonNode next = it.next(); if (next.isTextual()) { String text = next.asText(); if (!modules.contains(text)) { newModulesList.add(text); } } } ObjectNode oNode = (ObjectNode) node; if (newModulesList.size() > 0) { oNode.set("modules", newModulesList); } else { oNode.remove("modules"); } provider.write(node); } } }
Example 7
Source File: JsonConverterUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
public static List<JsonNode> getAppModelReferencedProcessModels(JsonNode appModelJson) { List<JsonNode> result = new ArrayList<>(); if (appModelJson.has("models")) { ArrayNode modelsArrayNode = (ArrayNode) appModelJson.get("models"); Iterator<JsonNode> modelArrayIterator = modelsArrayNode.iterator(); while (modelArrayIterator.hasNext()) { result.add(modelArrayIterator.next()); } } return result; }
Example 8
Source File: JsonConverterUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
protected static void internalGetBpmnProcessChildShapePropertyValues(JsonNode editorJsonNode, String propertyName, List<String> allowedStencilTypes, List<JsonLookupResult> result) { JsonNode childShapesNode = editorJsonNode.get("childShapes"); if (childShapesNode != null && childShapesNode.isArray()) { ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode; Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator(); while (childShapeNodeIterator.hasNext()) { JsonNode childShapeNode = childShapeNodeIterator.next(); String childShapeNodeStencilId = BpmnJsonConverterUtil.getStencilId(childShapeNode); boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId); if (readPropertiesNode) { // Properties JsonNode properties = childShapeNode.get("properties"); if (properties != null && properties.has(propertyName)) { JsonNode nameNode = properties.get("name"); JsonNode propertyNode = properties.get(propertyName); result.add(new JsonLookupResult(BpmnJsonConverterUtil.getElementId(childShapeNode), nameNode != null ? nameNode.asText() : null, propertyNode)); } } // Potential nested child shapes if (childShapeNode.has("childShapes")) { internalGetBpmnProcessChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result); } } } }
Example 9
Source File: DmnJsonConverterUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
protected static void internalGetDmnChildShapePropertyValues(JsonNode editorJsonNode, String propertyName, List<String> allowedStencilTypes, List<JsonLookupResult> result) { JsonNode childShapesNode = editorJsonNode.get("childShapes"); if (childShapesNode != null && childShapesNode.isArray()) { ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode; Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator(); while (childShapeNodeIterator.hasNext()) { JsonNode childShapeNode = childShapeNodeIterator.next(); String childShapeNodeStencilId = DmnJsonConverterUtil.getStencilId(childShapeNode); boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId); if (readPropertiesNode) { // Properties JsonNode properties = childShapeNode.get("properties"); if (properties != null && properties.has(propertyName)) { JsonNode nameNode = properties.get("name"); JsonNode propertyNode = properties.get(propertyName); result.add(new JsonLookupResult(DmnJsonConverterUtil.getElementId(childShapeNode), nameNode != null ? nameNode.asText() : null, propertyNode)); } } // Potential nested child shapes if (childShapeNode.has("childShapes")) { internalGetDmnChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result); } } } }
Example 10
Source File: JsonBuilderService.java From intellij-swagger with MIT License | 5 votes |
private void handleArrayNode( final ArrayNode root, final VirtualFile containingFile, final VirtualFile specFile) { final Iterator<JsonNode> iterator = root.iterator(); int index = 0; while (iterator.hasNext()) { final JsonNode current = iterator.next(); final JsonNode ref = current.get(SwaggerConstants.REF_KEY); if (ref != null && ref.isTextual()) { consumeRef((TextNode) ref, containingFile, new ArrayNodeConsumer(root, index), specFile); } index++; } }
Example 11
Source File: ConfigParser.java From deptective with Apache License 2.0 | 5 votes |
private List<PackagePattern> parseContains(ArrayNode arrayNode) { if (arrayNode == null) { return Collections.emptyList(); } Iterator<JsonNode> it = arrayNode.iterator(); List<PackagePattern> components = new ArrayList<>(); while (it.hasNext()) { components.add(PackagePattern.getPattern(it.next().asText())); } return components; }
Example 12
Source File: ConfigParser.java From deptective with Apache License 2.0 | 5 votes |
private List<String> parseReads(ArrayNode arrayNode) { if (arrayNode == null) { return Collections.emptyList(); } Iterator<JsonNode> it = arrayNode.iterator(); List<String> packages = new ArrayList<>(); while (it.hasNext()) { packages.add(it.next().asText()); } return packages; }
Example 13
Source File: JsonConverterUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static List<JsonNode> getAppModelReferencedProcessModels(JsonNode appModelJson) { List<JsonNode> result = new ArrayList<JsonNode>(); if (appModelJson.has("models")) { ArrayNode modelsArrayNode = (ArrayNode) appModelJson.get("models"); Iterator<JsonNode> modelArrayIterator = modelsArrayNode.iterator(); while (modelArrayIterator.hasNext()) { result.add(modelArrayIterator.next()); } } return result; }
Example 14
Source File: JsonConverterUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected static void internalGetBpmnProcessChildShapePropertyValues(JsonNode editorJsonNode, String propertyName, List<String> allowedStencilTypes, List<JsonLookupResult> result) { JsonNode childShapesNode = editorJsonNode.get("childShapes"); if (childShapesNode != null && childShapesNode.isArray()) { ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode; Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator(); while (childShapeNodeIterator.hasNext()) { JsonNode childShapeNode = childShapeNodeIterator.next(); String childShapeNodeStencilId = BpmnJsonConverterUtil.getStencilId(childShapeNode); boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId); if (readPropertiesNode) { // Properties JsonNode properties = childShapeNode.get("properties"); if (properties != null && properties.has(propertyName)) { JsonNode nameNode = properties.get("name"); JsonNode propertyNode = properties.get(propertyName); result.add(new JsonLookupResult(BpmnJsonConverterUtil.getElementId(childShapeNode), nameNode != null ? nameNode.asText() : null, propertyNode)); } } // Potential nested child shapes if (childShapeNode.has("childShapes")) { internalGetBpmnProcessChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result); } } } }
Example 15
Source File: ConfigParser.java From deptective with Apache License 2.0 | 5 votes |
private List<PackagePattern> parseContains(ArrayNode arrayNode) { if (arrayNode == null) { return Collections.emptyList(); } Iterator<JsonNode> it = arrayNode.iterator(); List<PackagePattern> components = new ArrayList<>(); while (it.hasNext()) { components.add(PackagePattern.getPattern(it.next().asText())); } return components; }
Example 16
Source File: ConfigParser.java From deptective with Apache License 2.0 | 5 votes |
private List<String> parseReads(ArrayNode arrayNode) { if (arrayNode == null) { return Collections.emptyList(); } Iterator<JsonNode> it = arrayNode.iterator(); List<String> packages = new ArrayList<>(); while (it.hasNext()) { packages.add(it.next().asText()); } return packages; }
Example 17
Source File: MetricVisualisation.java From scava with Eclipse Public License 2.0 | 4 votes |
public byte[] getSparky(DB db, BasicDBObject query) throws IOException, ParseException, UnsparkableVisualisationException { if (vis.get("timeSeries") == null || !vis.get("timeSeries").asBoolean()) { throw new UnsparkableVisualisationException(); } if (vis.get("series") != null) { throw new UnsparkableVisualisationException(); } if (vis.get("y").getNodeType().equals(JsonNodeType.ARRAY)) { throw new UnsparkableVisualisationException(); } ObjectMapper mapper = new ObjectMapper(); ObjectNode visualisation = mapper.createObjectNode(); chart.completeFields(visualisation, vis); String xColName = vis.get("x").asText(); String yColName = vis.get("y").asText(); yColName = yColName.replace("\"", ""); DBCollection collection = getCollection(db); ArrayNode datatable = chart.createDatatable(vis.get("datatable"), collection, query); Iterator<JsonNode> it = datatable.iterator(); List<Date> xdata = new ArrayList<>(); List<Double> ydata = new ArrayList<>(); // FIXME: This is hardcoded to Doubles SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); while (it.hasNext()) { JsonNode obj = it.next(); Date x = format.parse(obj.get(xColName).asText()); xdata.add(x); Double y = obj.path(yColName).asDouble(); ydata.add(y); } if (xdata.isEmpty()) { sparkData = mapper.createObjectNode(); sparkData.put("id", vis.path("id").textValue()); sparkData.put("name", vis.path("name").textValue()); sparkData.put("description", vis.path("description").textValue()); sparkData.put("status", "error"); sparkData.put("msg", "No data for metric."); return null; } // Spark config int height = 60; int width = 300; int padding = 12; // FIXME: Actually, for SCAVA sparklines, they HAVE to have // Date as the X-axis! DateDimension xdim = new DateDimension(xdata, width-padding, padding); LinearDimension ydim = new LinearDimension(ydata, height-padding, padding); Sparkle sparkle = new Sparkle(height, width, padding); sparkle.setHeadless(true); byte[] bytes = sparkle.renderToByteArray(xdim, ydim); DateFormat outputDateFormat = new SimpleDateFormat("dd/MM/yy"); // Set the spark data sparkData = mapper.createObjectNode(); sparkData.put("status", "ok"); sparkData.put("id", vis.path("id").textValue()); sparkData.put("name", vis.path("name").textValue()); sparkData.put("description", vis.path("description").textValue()); sparkData.put("low", ydim.getMinValue()); sparkData.put("high", ydim.getMaxValue()); sparkData.put("first", ydata.get(0)); sparkData.put("last", ydata.get(ydata.size()-1)); sparkData.put("firstDate", outputDateFormat.format(xdata.get(0))); sparkData.put("lastDate", outputDateFormat.format(xdata.get(xdata.size()-1))); sparkData.put("months", (int)((xdata.get(xdata.size()-1).getTime() - xdata.get(0).getTime())/(365.24 * 24 * 60 * 60 * 1000 / 12))); return bytes; }
Example 18
Source File: RemoveProvidersYMLAction.java From walkmod-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void doAction(JsonNode node) throws Exception { HashSet<String> providerSet = new HashSet<String>(); for (String elem : providers) { String[] partsType = elem.split(":"); if (partsType.length == 1) { elem = "org.walkmod:walkmod-" + elem + "-plugin:" + elem; } if (partsType.length != 3 && partsType.length != 1) { throw new TransformerException("Invalid conf-provider"); } providerSet.add(elem); } if (node.has("conf-providers")) { JsonNode aux = node.get("conf-providers"); if (aux.isArray()) { ArrayNode providersList = (ArrayNode) node.get("conf-providers"); Iterator<JsonNode> it = providersList.iterator(); ArrayNode newProvidersList = new ArrayNode(provider.getObjectMapper().getNodeFactory()); while (it.hasNext()) { JsonNode next = it.next(); if (next.isObject()) { String type = next.get("type").asText(); String[] parts = type.split(":"); if (parts.length == 1) { type = "org.walkmod:walkmod-" + type + "-plugin:" + type; } else if (parts.length != 3) { throw new TransformerException("Invalid conf-provider"); } if (!providerSet.contains(type)) { newProvidersList.add(next); } } } ObjectNode oNode = (ObjectNode) node; if (newProvidersList.size() > 0) { oNode.set("conf-providers", newProvidersList); } else { oNode.remove("conf-providers"); } provider.write(node); } } }
Example 19
Source File: RemoveProvidersYMLAction.java From walkmod-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void doAction(JsonNode node) throws Exception { HashSet<String> providerSet = new HashSet<String>(); for (String elem : providers) { String[] partsType = elem.split(":"); if (partsType.length == 1) { elem = "org.walkmod:walkmod-" + elem + "-plugin:" + elem; } if (partsType.length != 3 && partsType.length != 1) { throw new TransformerException("Invalid conf-provider"); } providerSet.add(elem); } if (node.has("conf-providers")) { JsonNode aux = node.get("conf-providers"); if (aux.isArray()) { ArrayNode providersList = (ArrayNode) node.get("conf-providers"); Iterator<JsonNode> it = providersList.iterator(); ArrayNode newProvidersList = new ArrayNode(provider.getObjectMapper().getNodeFactory()); while (it.hasNext()) { JsonNode next = it.next(); if (next.isObject()) { String type = next.get("type").asText(); String[] parts = type.split(":"); if (parts.length == 1) { type = "org.walkmod:walkmod-" + type + "-plugin:" + type; } else if (parts.length != 3) { throw new TransformerException("Invalid conf-provider"); } if (!providerSet.contains(type)) { newProvidersList.add(next); } } } ObjectNode oNode = (ObjectNode) node; if (newProvidersList.size() > 0) { oNode.set("conf-providers", newProvidersList); } else { oNode.remove("conf-providers"); } provider.write(node); } } }
Example 20
Source File: JsonArrayValueDeserializer.java From kieker with Apache License 2.0 | 2 votes |
/** * Constructor for a serializer. * * @param array * input array node */ protected JsonArrayValueDeserializer(final ArrayNode array) { this.values = array.iterator(); }