/** * Main constructor * * @param baseNode the base node * @param pointer the pointer into the base node */ protected BaseJsonTree(final JsonNode baseNode, final JsonPointer pointer) { this.baseNode = baseNode; node = pointer.path(baseNode); this.pointer = pointer; }
/** * Main constructor * * @param baseNode the base node * @param pointer the pointer into the base node */ protected BaseJsonTree(final JsonNode baseNode, final JsonPointer pointer) { this.baseNode = baseNode; node = pointer.path(baseNode); this.pointer = pointer; }
/** * Main constructor * * @param baseNode the base node * @param pointer the pointer into the base node */ protected BaseJsonTree(final JsonNode baseNode, final JsonPointer pointer) { this.baseNode = baseNode; node = pointer.path(baseNode); this.pointer = pointer; }
// All of these are thread safe private static final ObjectReader READER = JacksonUtils.getReader(); private static final JsonPointer NAME_POINTER = JsonPointer.of("name"); private static final JsonPointer WINDOWS_POINTER = JsonPointer.of("extract", "native", "windows"); // Fetch content from URL final JsonNode content = READER.readTree(url.getInputStream()); // Get content at pointers, if any final JsonNode nameNode = NAME_POINTER.path(content); final JsonNode windowsNode = WINDOWS_POINTER.path(content);
private void doSetPointer(final JsonPointer pointer) { currentPointer = pointer; currentNode = currentPointer.path(baseNode); Preconditions.checkArgument(!currentNode.isMissingNode(), "base node has no element at pointer " + currentPointer); }
@Override public JsonPointer matchingPointer(final JsonRef ref) { final JsonPointer ret = getMatchingPointer(ref); if (ret == null) return null; return ret.path(baseNode).isMissingNode() ? null : ret; }
@Override public JsonPointer matchingPointer(final JsonRef ref) { final JsonPointer ret = getMatchingPointer(ref); if (ret == null) return null; return ret.path(baseNode).isMissingNode() ? null : ret; }
@Override public JsonPointer matchingPointer(final JsonRef ref) { final JsonPointer ret = getMatchingPointer(ref); if (ret == null) return null; return ret.path(baseNode).isMissingNode() ? null : ret; }
@Nullable @Override public JsonPointer matchingPointer(final JsonRef ref) { if (!ref.isLegal()) return null; final JsonPointer ptr = ref.getPointer(); return ptr.path(baseNode).isMissingNode() ? null : ptr; } }
@Nullable @Override public JsonPointer matchingPointer(final JsonRef ref) { if (!ref.isLegal()) return null; final JsonPointer ptr = ref.getPointer(); return ptr.path(baseNode).isMissingNode() ? null : ptr; } }
@Nullable @Override public JsonPointer matchingPointer(final JsonRef ref) { if (!ref.isLegal()) return null; final JsonPointer ptr = ref.getPointer(); return ptr.path(baseNode).isMissingNode() ? null : ptr; } }
protected BaseSchemaTree(final SchemaKey key, final JsonNode baseNode, final JsonPointer pointer) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(baseNode); Preconditions.checkNotNull(pointer); this.key = key; dollarSchema = extractDollarSchema(baseNode); this.baseNode = baseNode; this.pointer = pointer; node = pointer.path(baseNode); final JsonRef loadingRef = key.getLoadingRef(); final JsonRef ref = idFromNode(baseNode); startingRef = ref == null ? loadingRef : loadingRef.resolve(ref); currentRef = nextRef(startingRef, pointer, baseNode); }
protected BaseSchemaTree(final SchemaKey key, final JsonNode baseNode, final JsonPointer pointer) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(baseNode); Preconditions.checkNotNull(pointer); this.key = key; dollarSchema = extractDollarSchema(baseNode); this.baseNode = baseNode; this.pointer = pointer; node = pointer.path(baseNode); final JsonRef loadingRef = key.getLoadingRef(); final JsonRef ref = idFromNode(baseNode); startingRef = ref == null ? loadingRef : loadingRef.resolve(ref); currentRef = nextRef(startingRef, pointer, baseNode); }
protected BaseSchemaTree(final SchemaKey key, final JsonNode baseNode, final JsonPointer pointer) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(baseNode); Preconditions.checkNotNull(pointer); this.key = key; dollarSchema = extractDollarSchema(baseNode); this.baseNode = baseNode; this.pointer = pointer; node = pointer.path(baseNode); final JsonRef loadingRef = key.getLoadingRef(); final JsonRef ref = idFromNode(baseNode); startingRef = ref == null ? loadingRef : loadingRef.resolve(ref); currentRef = nextRef(startingRef, pointer, baseNode); }
@Deprecated protected BaseSchemaTree(final JsonRef loadingRef, final JsonNode baseNode, final JsonPointer pointer) { dollarSchema = extractDollarSchema(baseNode); key = loadingRef.equals(JsonRef.emptyRef()) ? SchemaKey.anonymousKey() : SchemaKey.forJsonRef(loadingRef); this.baseNode = baseNode; this.pointer = pointer; node = pointer.path(baseNode); final JsonRef ref = idFromNode(baseNode); startingRef = ref == null ? loadingRef : loadingRef.resolve(ref); currentRef = nextRef(startingRef, pointer, baseNode); }
@Deprecated protected BaseSchemaTree(final JsonRef loadingRef, final JsonNode baseNode, final JsonPointer pointer) { dollarSchema = extractDollarSchema(baseNode); key = loadingRef.equals(JsonRef.emptyRef()) ? SchemaKey.anonymousKey() : SchemaKey.forJsonRef(loadingRef); this.baseNode = baseNode; this.pointer = pointer; node = pointer.path(baseNode); final JsonRef ref = idFromNode(baseNode); startingRef = ref == null ? loadingRef : loadingRef.resolve(ref); currentRef = nextRef(startingRef, pointer, baseNode); }
@Override public JsonNode apply(final JsonNode node) throws JsonPatchException { final JsonNode dupData = from.path(node).deepCopy(); if (dupData.isMissingNode()) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.noSuchPath")); return new AddOperation(path, dupData).apply(node); } }
@Deprecated protected BaseSchemaTree(final JsonRef loadingRef, final JsonNode baseNode, final JsonPointer pointer) { dollarSchema = extractDollarSchema(baseNode); key = loadingRef.equals(JsonRef.emptyRef()) ? SchemaKey.anonymousKey() : SchemaKey.forJsonRef(loadingRef); this.baseNode = baseNode; this.pointer = pointer; node = pointer.path(baseNode); final JsonRef ref = idFromNode(baseNode); startingRef = ref == null ? loadingRef : loadingRef.resolve(ref); currentRef = nextRef(startingRef, pointer, baseNode); }
@Override public JsonNode apply(final JsonNode node) throws JsonPatchException { final JsonNode tested = path.path(node); if (tested.isMissingNode()) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.noSuchPath")); if (!EQUIVALENCE.equivalent(tested, value)) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.valueTestFailure")); return node.deepCopy(); } }
@Override public JsonNode apply(final JsonNode node) throws JsonPatchException { if (from.equals(path)) return node.deepCopy(); final JsonNode movedNode = from.path(node); if (movedNode.isMissingNode()) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.noSuchPath")); final JsonPatchOperation remove = new RemoveOperation(from); final JsonPatchOperation add = new AddOperation(path, movedNode); return add.apply(remove.apply(node)); } }