public static JsonNode searchJson(JsonNode tree, String searchKey) throws JsonProcessingException, IOException { if (tree == null) { return null; } if(tree.has(searchKey)) { return tree.get(searchKey); } if(tree.isContainerNode()) { for(JsonNode branch: tree) { JsonNode branchResult = searchJson(branch, searchKey); if (branchResult != null && !branchResult.isMissingNode()) { return branchResult; } } } return null; }
@Override public Object getField(String fieldName) { JsonNode fn = jn.get(fieldName); if (fn.isContainerNode()) { AtomicInteger idx = new AtomicInteger(0); List<Field> fields = Lists.newArrayList(fn.fieldNames()) .stream() .map(f -> new Field(f, idx.getAndIncrement())) .collect(Collectors.toList()); return new GenericJsonRecord(fields, fn); } else if (fn.isBoolean()) { return fn.asBoolean(); } else if (fn.isInt()) { return fn.asInt(); } else if (fn.isFloatingPointNumber()) { return fn.asDouble(); } else if (fn.isDouble()) { return fn.asDouble(); } else { return fn.asText(); } } }
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) { if (!(source instanceof JsonNode)) { resultMap.put(propertyPrefix, source); return; } JsonNode element = (JsonNode) source; if (element.isArray()) { Iterator<JsonNode> nodes = element.elements(); while (nodes.hasNext()) { JsonNode cur = nodes.next(); if (cur.isArray()) { this.falttenCollection(propertyPrefix, cur.elements(), resultMap); } } } else if (element.isContainerNode()) { this.doFlatten(propertyPrefix, element.fields(), resultMap); } else { resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value")); } }
if (value.isContainerNode()) { fieldValue = value.toString(); } else if (value.isFloatingPointNumber()) {
if (valueNode == null || !valueNode.isContainerNode()) { return valueNode;
if (node.isContainerNode()) { if (node.isArray()) processArray(report, data);
@Override protected boolean hasChildren(JsonNode node) { return node.isContainerNode() && node.size() > 0; } }
@Override protected boolean hasChildren(JsonNode node) { return node.isContainerNode() && node.size() > 0; } }
/** * @since 5.8-HF01 */ private String extractValueFromNode(JsonNode node, ObjectMapper om) throws IOException { if (!node.isNull()) { return node.isContainerNode() ? om.writeValueAsString(node) : node.asText(); } else { return null; } }
private void readProperties(MutableRepresentation resource, JsonNode rootNode) throws IOException { Iterator<String> fieldNames = rootNode.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); if (!Support.RESERVED_JSON_PROPERTIES.contains(fieldName)) { JsonNode field = rootNode.get(fieldName); resource.withProperty(fieldName, field.isNull() ? null : ( field.isContainerNode() ? field.toString() : field.asText())); } } }
/** * Returns <code>true</code> in case 'DATA' note has 'ID' and 'TYPE' attributes. * @param dataNode relationship data node * @return <code>true</code> if node has required attributes, else <code>false</code> */ public static boolean isRelationshipParsable(JsonNode dataNode) { return dataNode != null && dataNode.hasNonNull(JSONAPISpecConstants.ID) && dataNode.hasNonNull(JSONAPISpecConstants.TYPE) && !dataNode.get(JSONAPISpecConstants.ID).isContainerNode() && !dataNode.get(JSONAPISpecConstants.TYPE).isContainerNode(); }
/** * Returns <code>true</code> in case 'DATA' note has 'ID' and 'TYPE' attributes. * @param dataNode relationship data node * @return <code>true</code> if node has required attributes, else <code>false</code> */ public static boolean isRelationshipParsable(JsonNode dataNode) { return dataNode != null && dataNode.hasNonNull(JSONAPISpecConstants.ID) && dataNode.hasNonNull(JSONAPISpecConstants.TYPE) && !dataNode.get(JSONAPISpecConstants.ID).isContainerNode() && !dataNode.get(JSONAPISpecConstants.TYPE).isContainerNode(); }
private void extract(String attributeName, JsonNode node, List<Long> results) { JsonNode n = node.get(attributeName); if (n != null) { Long l = n.asLong(); if (!results.contains(l)) { results.add(l); } } if (node.isContainerNode()) { toList(node.elements()).stream().forEach(cn -> extract(attributeName, cn, results)); } }
@Override public JsonNode get(final JsonNode node) { if (node == null || !node.isContainerNode()) return null; final String raw = token.getRaw(); return node.isObject() ? node.get(raw) : node.get(arrayIndexFor(raw)); }
@Override public JsonNode get(final JsonNode node) { if (node == null || !node.isContainerNode()) return null; final String raw = token.getRaw(); return node.isObject() ? node.get(raw) : node.get(arrayIndexFor(raw)); }
void valueAdded(final JsonPointer pointer, final JsonNode value) { final JsonPatchOperation op; if (value.isContainerNode()) { // Use copy operation only for container nodes. final JsonPointer ptr = findUnchangedValue(value); op = ptr != null ? new CopyOperation(ptr, pointer) : new AddOperation(pointer, value); } else { op = new AddOperation(pointer, value); } diffs.add(op); }
void valueAdded(final JsonPointer pointer, final JsonNode value) { final JsonPatchOperation op; if (value.isContainerNode()) { // Use copy operation only for container nodes. final JsonPointer ptr = findUnchangedValue(value); op = ptr != null ? new CopyOperation(ptr, pointer) : new AddOperation(pointer, value); } else { op = new AddOperation(pointer, value); } diffs.add(op); }
void valueAdded(final JsonPointer pointer, final JsonNode value) { final JsonPatchOperation op; if (value.isContainerNode()) { // Use copy operation only for container nodes. final JsonPointer ptr = findUnchangedValue(value); op = ptr != null ? new CopyOperation(ptr, pointer) : new AddOperation(pointer, value); } else { op = new AddOperation(pointer, value); } diffs.add(op); }
/** * Fails if the subject is not a container with the specified number of values or name/value pairs. */ public void hasLength(int length) { // TODO Support string length? checkArgument(length >= 0, "length (%s) must be >= 0", length); if (actual() == null || !actual().isContainerNode()) { fail("is a container"); } else if (actual().size() != length) { fail("has length", length); } }
/** * Fails if the subject is a container with one ore more values or name/value pairs. */ public void isEmpty() { if (actual() == null || !actual().isContainerNode()) { fail("is a container"); } else if (actual().size() != 0) { fail("is empty"); } }