/** * Build an instance validator tied to a schema * * <p>Note that the validity of the schema is <b>not</b> checked. Use {@link * #getSyntaxValidator()} if you are not sure.</p> * * @param schema the schema * @return a {@link JsonSchema} * @throws ProcessingException schema is a {@link MissingNode} * @throws NullPointerException schema is null */ public JsonSchema getJsonSchema(final JsonNode schema) throws ProcessingException { BUNDLE.checkNotNull(schema, "nullSchema"); return validator.buildJsonSchema(schema, JsonPointer.empty()); }
@Test(timeOut = 1000) public void circularReferencingDuringValidationIsDetected() throws IOException, ProcessingException, JsonPointerException { final JsonNode schemaNode = JsonLoader.fromResource("/other/issue102.json"); final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonValidator validator = factory.getValidator(); final MessageBundle bundle = MessageBundles.getBundle(JsonSchemaValidationBundle.class); try { validator.validate(schemaNode, JacksonUtils.nodeFactory().nullNode()); fail("No exception thrown!"); } catch (ProcessingException e) { final URI uri = URI.create("#/oneOf/1"); final ProcessingMessage message = e.getProcessingMessage(); final String expectedMessage = bundle.printf("err.common.validationLoop", uri, ""); assertMessage(message) .hasMessage(expectedMessage) .hasField("alreadyVisited", uri) .hasField("instancePointer", JsonPointer.empty().toString()) .hasField("validationPath", Arrays.asList("#", "#/oneOf/1")); } assertTrue(true); }
/** * Main constructor * * @param key the schema key * @param baseNode the base node */ public CanonicalSchemaTree(final SchemaKey key, final JsonNode baseNode) { super(key, baseNode, JsonPointer.empty()); }
/** * Protected constructor * * <p>This is equivalent to calling {@link * BaseJsonTree#BaseJsonTree(JsonNode, JsonPointer)} with an empty pointer. * </p> * * @param baseNode the base node */ protected BaseJsonTree(final JsonNode baseNode) { this(baseNode, JsonPointer.empty()); }
/** * Main constructor * * @param key the schema key * @param baseNode the base node */ public CanonicalSchemaTree(final SchemaKey key, final JsonNode baseNode) { super(key, baseNode, JsonPointer.empty()); }
/** * Main constructor * * @param key the schema key * @param baseNode the base node */ public CanonicalSchemaTree(final SchemaKey key, final JsonNode baseNode) { super(key, baseNode, JsonPointer.empty()); }
/** * Protected constructor * * <p>This is equivalent to calling {@link * BaseJsonTree#BaseJsonTree(JsonNode, JsonPointer)} with an empty pointer. * </p> * * @param baseNode the base node */ protected BaseJsonTree(final JsonNode baseNode) { this(baseNode, JsonPointer.empty()); }
/** * Protected constructor * * <p>This is equivalent to calling {@link * BaseJsonTree#BaseJsonTree(JsonNode, JsonPointer)} with an empty pointer. * </p> * * @param baseNode the base node */ protected BaseJsonTree(final JsonNode baseNode) { this(baseNode, JsonPointer.empty()); }
@VisibleForTesting static Map<JsonPointer, JsonNode> getUnchangedValues(final JsonNode source, final JsonNode target) { final Map<JsonPointer, JsonNode> ret = Maps.newHashMap(); computeUnchanged(ret, JsonPointer.empty(), source, target); return ret; }
/** * Main constructor * * @param key the schema key * @param baseNode the base node */ public InlineSchemaTree(final SchemaKey key, final JsonNode baseNode) { super(key, baseNode, JsonPointer.empty()); final Map<JsonRef, JsonPointer> abs = Maps.newHashMap(); final Map<JsonRef, JsonPointer> other = Maps.newHashMap(); final JsonRef loadingRef = key.getLoadingRef(); walk(loadingRef, baseNode, JsonPointer.empty(), abs, other); absRefs = ImmutableMap.copyOf(abs); otherRefs = ImmutableMap.copyOf(other); }
/** * Main constructor * * @param key the schema key * @param baseNode the base node */ public InlineSchemaTree(final SchemaKey key, final JsonNode baseNode) { super(key, baseNode, JsonPointer.empty()); final Map<JsonRef, JsonPointer> abs = Maps.newHashMap(); final Map<JsonRef, JsonPointer> other = Maps.newHashMap(); final JsonRef loadingRef = key.getLoadingRef(); walk(loadingRef, baseNode, JsonPointer.empty(), abs, other); absRefs = ImmutableMap.copyOf(abs); otherRefs = ImmutableMap.copyOf(other); }
/** * Main constructor * * @param key the schema key * @param baseNode the base node */ public InlineSchemaTree(final SchemaKey key, final JsonNode baseNode) { super(key, baseNode, JsonPointer.empty()); final Map<JsonRef, JsonPointer> abs = Maps.newHashMap(); final Map<JsonRef, JsonPointer> other = Maps.newHashMap(); final JsonRef loadingRef = key.getLoadingRef(); walk(loadingRef, baseNode, JsonPointer.empty(), abs, other); absRefs = ImmutableMap.copyOf(abs); otherRefs = ImmutableMap.copyOf(other); }
JsonPointer ptr; try { ptr = fragment.isEmpty() ? JsonPointer.empty() : new JsonPointer(fragment); } catch (JsonPointerException ignored) {
JsonPointer ptr; try { ptr = fragment.isEmpty() ? JsonPointer.empty() : new JsonPointer(fragment); } catch (JsonPointerException ignored) {
JsonPointer ptr; try { ptr = fragment.isEmpty() ? JsonPointer.empty() : new JsonPointer(fragment); } catch (JsonPointerException ignored) {
@Test public void initializedNodeTreeReturnsCorrectNodeAndPointer() { final JsonTree tree = new SimpleJsonTree(testNode); assertSame(tree.getNode(), testNode); assertEquals(tree.getPointer(), JsonPointer.empty()); }
@Test public void removingRootReturnsMissingNode() throws JsonPatchException { final JsonNode node = JacksonUtils.nodeFactory().nullNode(); final JsonPatchOperation op = new RemoveOperation(JsonPointer.empty()); final JsonNode ret = op.apply(node); assertTrue(ret.isMissingNode()); } }
/** * Generate a JSON patch for transforming the source node into the target * node * * @param source the node to be patched * @param target the expected result after applying the patch * @return the patch as a {@link JsonPatch} * * @since 1.9 */ public static JsonPatch asJsonPatch(final JsonNode source, final JsonNode target) { BUNDLE.checkNotNull(source, "common.nullArgument"); BUNDLE.checkNotNull(target, "common.nullArgument"); final Map<JsonPointer, JsonNode> unchanged = getUnchangedValues(source, target); final DiffProcessor processor = new DiffProcessor(unchanged); generateDiffs(processor, JsonPointer.empty(), source, target); return processor.getPatch(); }
@Test(dataProvider = "getContexts") public void pointerSetCorrectlyCalculatesContext(final String path, final String s) throws JsonPointerException, JsonReferenceException { final JsonPointer ptr = new JsonPointer(path); final JsonRef scope = JsonRef.fromString(s); SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final JsonRef origRef = tree.getContext(); tree = tree.setPointer(ptr); assertEquals(tree.getContext(), scope); tree = tree.setPointer(JsonPointer.empty()); assertEquals(tree.getContext(), origRef); }