/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }
@Override protected JsonOverlay<?> _findInternal(JsonPointer path) { String key = path.getMatchingProperty(); return overlays.containsKey(key) ? overlays.get(key)._find(path.tail()) : null; }
@Override protected JsonOverlay<?> _findInternal(JsonPointer path) { int index = path.getMatchingIndex(); return index >= 0 && overlays.size() > index ? overlays.get(index)._find(path.tail()) : null; }
result.add(i); currentJson = currentJson.get(key); pointer = pointer.tail(); break;
@Override public JsonOverlay<?> _findInternal(JsonPointer path) { if (path.matchesProperty("additionalProperties")) { return path.tail().matches() ? _getOverlay("additionalProperties", BooleanOverlay.class) : _get("additionalPropertiesSchema", SchemaImpl.class)._findInternal(path.tail()); } else { return super._findInternal(path); } }
@Override public JsonOverlay<?> _findInternal(JsonPointer path) { if (path.matchesProperty("additionalProperties")) { return path.tail().matches() ? _getOverlay("additionalProperties", BooleanOverlay.class) : _get("additionalPropertiesSchema", SchemaImpl.class)._findInternal(path.tail()); } else { return super._findInternal(path); } }
int i = p.getMatchingIndex(); if (i >= 0) { if (p.tail().matches() || !tree.has(i)) { ((ArrayNode) tree).set(i, buildTree(p.tail(), value)); return; } else { if (p.tail().matches() || !tree.has(prop)) { ((ObjectNode) tree).set(prop, buildTree(p.tail(), value)); return; } else { tree = ((ObjectNode) tree).get(prop); p = p.tail();
@Override public JsonOverlay<?> _findInternal(JsonPointer path) { if (path.matchesProperty("additionalProperties")) { return path.tail().matches() ? _getOverlay("additionalProperties", BooleanOverlay.class) : _get("additionalPropertiesSchema", SchemaImpl.class)._findInternal(path.tail()); } else { return super._findInternal(path); } }
private JsonNode _injectChild(JsonNode node, JsonNode child, JsonPointer pointer) { if (pointer.matches()) { // inject into current node, which means: // * If current is missing, return child // * If current and child are both objects, merge child into current // * Otherwise error if (node.isMissingNode()) { return child; } else if (node.isObject() && child.isObject()) { ((ObjectNode) node).setAll((ObjectNode) child); return node; } else { throw new IllegalArgumentException(); } } else if (node.isObject() || node.isMissingNode()) { String name = pointer.getMatchingProperty(); JsonNode childNode = _injectChild(node.path(name), child, pointer.tail()); if (!childNode.isMissingNode()) { node = node.isObject() ? node : _jsonObject(); ((ObjectNode) node).set(name, childNode); } return node; } else { // can't add a property name to a non-object throw new IllegalArgumentException(); } }
/** * Build a JsonNode tree to contain the given value at the given JsonPointer * path. Empty array and object nodes are created and nested as needed. * * @param p a JsonPointer indicating where the value is to appear in the * resulting structure * @param value the value to embed in the structure * @return the created structure */ private JsonNode buildTree(JsonPointer p, JsonNode value) { if (p.matches()) { return value; } else if (p.getMatchingIndex() >= 0) { ArrayNode result = JsonNodeFactory.instance.arrayNode(); result.set(p.getMatchingIndex(), buildTree(p.tail(), value)); return result; } else { ObjectNode result = JsonNodeFactory.instance.objectNode(); result.set(p.getMatchingProperty(), buildTree(p.tail(), value)); return result; } }
/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }
/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }
/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }
/** * Method for locating node specified by given JSON pointer instances. * Method will never return null; if no matching node exists, * will return a node for which {@link #isMissingNode()} returns true. * * @return Node that matches given JSON Pointer: if no match exists, * will return a node for which {@link #isMissingNode()} returns true. * * @since 2.3 */ @Override public final JsonNode at(JsonPointer ptr) { // Basically: value nodes only match if we have "empty" path left if (ptr.matches()) { return this; } JsonNode n = _at(ptr); if (n == null) { return MissingNode.getInstance(); } return n.at(ptr.tail()); }