/** * This method here expands our horizons in writing code that sucks. * JsonNodes have no parent pointer, so finding a parent involves iterating * all nodes with the hope of finding the node, and returning the container * that contains it. * * The whole JsonNode thing should be reengineered at some point. */ public static JsonNode findParent(final JsonNode root, final JsonNode node) { if (root instanceof ContainerNode) { for (Iterator<JsonNode> itr = root.elements(); itr.hasNext();) { JsonNode child = itr.next(); if (child == node) { return root; } else { JsonNode found = findParent(child, node); if (found != null) { return found; } } } } return null; }
/** * This method here expands our horizons in writing code that sucks. * JsonNodes have no parent pointer, so finding a parent involves iterating * all nodes with the hope of finding the node, and returning the container * that contains it. * * The whole JsonNode thing should be reengineered at some point. */ public static JsonNode findParent(final JsonNode root, final JsonNode node) { if (root instanceof ContainerNode) { for (Iterator<JsonNode> itr = root.elements(); itr.hasNext();) { JsonNode child = itr.next(); if (child == node) { return root; } else { JsonNode found = findParent(child, node); if (found != null) { return found; } } } } return null; }
continue; } else if (name.equals(Path.PARENT)) { output = findParent(root, output); if (output instanceof ArrayNode) { output = findParent(root, output);
continue; } else if (name.equals(Path.PARENT)) { output = findParent(root, output); if (output instanceof ArrayNode) { output = findParent(root, output);