@Override protected JsonNode _at(JsonPointer ptr) { return get(ptr.getMatchingProperty()); }
@Override protected JsonNode _at(JsonPointer ptr) { return get(ptr.getMatchingProperty()); }
@Override protected JsonNode _at(JsonPointer ptr) { return get(ptr.getMatchingProperty()); }
@Override protected JsonNode _at(JsonPointer ptr) { return get(ptr.getMatchingProperty()); }
@Override protected JsonNode _at(JsonPointer ptr) { return get(ptr.getMatchingProperty()); }
@Override protected JsonOverlay<?> _findInternal(JsonPointer path) { String key = path.getMatchingProperty(); return overlays.containsKey(key) ? overlays.get(key)._find(path.tail()) : null; }
static JsonNode addToObject(final JsonPointer path, final JsonNode node, final JsonNode value) { final ObjectNode target = (ObjectNode) node.at(path.head()); target.set(path.last().getMatchingProperty(), value); return node; } }
static JsonNode addToObject(final JsonPointer path, final JsonNode node, final JsonNode value) { final ObjectNode target = (ObjectNode) node.at(path.head()); target.set(path.last().getMatchingProperty(), value); return node; } }
static JsonNode addToObject(final JsonPointer path, final JsonNode node, final JsonNode value) { final ObjectNode target = (ObjectNode) node.at(path.head()); target.set(path.last().getMatchingProperty(), value); return node; } }
@Override JsonNode apply(final JsonNode node) { ensureExistence(node); final JsonNode replacement = valueCopy(); if (path.toString().isEmpty()) { return replacement; } final JsonNode parent = node.at(path.head()); final String rawToken = path.last().getMatchingProperty(); if (parent.isObject()) { ((ObjectNode) parent).set(rawToken, replacement); } else { ((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement); } return node; } }
@Override JsonNode apply(final JsonNode node) { ensureExistence(node); final JsonNode replacement = valueCopy(); if (path.toString().isEmpty()) { return replacement; } final JsonNode parent = node.at(path.head()); final String rawToken = path.last().getMatchingProperty(); if (parent.isObject()) { ((ObjectNode) parent).set(rawToken, replacement); } else { ((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement); } return node; } }
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } ensureExistence(node); final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } ensureExistence(node); final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } final JsonNode found = node.at(path); if (found.isMissingNode()) { return node; } final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else if (parentNode.isArray()) { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } ensureExistence(node); final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
@Override JsonNode apply(JsonNode node) { final JsonNode actual = ensureExistence(node); if (!EQUIVALENCE.equivalent(actual, oldValue)) { throw new JsonPatchException("mismatching value at '" + path + "': " + actual + " (expected: " + oldValue + ')'); } final JsonNode replacement = newValue.deepCopy(); if (path.toString().isEmpty()) { return replacement; } final JsonNode parent = node.at(path.head()); final String rawToken = path.last().getMatchingProperty(); if (parent.isObject()) { ((ObjectNode) parent).set(rawToken, replacement); } else { ((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement); } return node; }
private boolean matchesPath(JsonOverlay<?> child, JsonPointer path) { JsonPointer childPath = getPointer(child); while (!childPath.matches()) { if (!childPath.matchesProperty(path.getMatchingProperty())) { return false; } else { path = path.tail(); childPath = childPath.tail(); } } return true; }
@Override JsonNode apply(final JsonNode node) { if (path.toString().isEmpty()) { return MissingNode.getInstance(); } final JsonNode found = node.at(path); if (found.isMissingNode()) { return node; } final JsonNode parentNode = node.at(path.head()); final String raw = path.last().getMatchingProperty(); if (parentNode.isObject()) { ((ObjectNode) parentNode).remove(raw); } else if (parentNode.isArray()) { ((ArrayNode) parentNode).remove(Integer.parseInt(raw)); } return node; }
@Override JsonNode apply(JsonNode node) { final JsonNode actual = ensureExistence(node); if (!EQUIVALENCE.equivalent(actual, oldValue)) { throw new JsonPatchException("mismatching value at '" + path + "': " + actual + " (expected: " + oldValue + ')'); } final JsonNode replacement = newValue.deepCopy(); if (path.toString().isEmpty()) { return replacement; } final JsonNode parent = node.at(path.head()); final String rawToken = path.last().getMatchingProperty(); if (parent.isObject()) { ((ObjectNode) parent).set(rawToken, replacement); } else { ((ArrayNode) parent).set(Integer.parseInt(rawToken), replacement); } return node; }
/** * 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; } }