You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* noting in introduction that this is the only implementation which supports Draft 6
* installation method: changing to jitpack
* section about draft-4 and draft-6
* schemaLocation docs
* listing new formats
*[JSON report of the failures](#json-report-of-the-failures)
@@ -13,7 +14,7 @@
13
14
*[Resolution scopes](#resolution-scopes)
14
15
15
16
16
-
This project is an implementation of the [JSON Schema Core Draft v4][draft-zyp-json-schema-04]specification.
17
+
This project is an implementation of the JSON Schema [Draft v4][draft-zyp-json-schema-04]and [Draft-6](https://tools.ietf.org/html/draft-wright-json-schema-01) specifications.
17
18
It uses the [org.json API](http://stleary.github.io/JSON-java/) (created by Douglas Crockford) for representing JSON data.
18
19
19
20
# When to use this library?
@@ -23,6 +24,7 @@ But - as you may have already discovered - there is also an [other Java implemen
23
24
of the JSON Schema specification. So here are some advices about which one to use:
24
25
* if you use Jackson to handle JSON in Java code, then [daveclayton/json-schema-validator] is obviously a better choice, since it uses Jackson
25
26
* if you want to use the [org.json API](http://www.json.org/java/) then this library is the better choice
27
+
* if you need JSON Schema Draft 6 support, then you need this library.
26
28
* if you want to use anything else for handling JSON (like GSON or javax.json), then you are in a little trouble, since
27
29
currently there is no schema validation library backed by these libraries. It means that you will have to parse the JSON
28
30
twice: once for the schema validator, and once for your own processing. In a case like that, this library is probably still
@@ -37,12 +39,21 @@ Add the following to your `pom.xml`:
The best way to denote the JSON Schema version you want to use is to include its meta-schema URL in the document root with the `"$schema"` key. This is a common notation, facilitated by the library to determine which version should be used.
88
+
89
+
Quick reference:
90
+
* if there is `"$schema": "http://json-schema.org/draft-04/schema"` in the schema root, then Draft 4 will be used
91
+
* if there is `"$schema": "http://json-schema.org/draft-06/schema"` in the schema root, then Draft 6 will be used
92
+
* if none of these is found then Draft 4 will be assumed as default
93
+
94
+
If you want to specify the meta-schema version explicitly then you can change the default from Draft 4 to Draft 6 by configuring the loader this way:
95
+
96
+
```java
97
+
SchemaLoader loader =SchemaLoader.builder()
98
+
.schemaJson(yourSchemaJSON)
99
+
.draftV6Support()
100
+
.build();
101
+
Schema schema = loader.load().build();
102
+
```
103
+
74
104
## Investigating failures
75
105
76
106
@@ -169,9 +199,13 @@ following keys:
169
199
*`"keyword"`: the JSON Schema keyword which was violated
170
200
*`"pointerToViolation"`: a JSON Pointer denoting the path from the input document root to its fragment which caused
171
201
the validation failure
202
+
*`"schemaLocation"`: a JSON Pointer denoting the path from the schema JSON root to the violated keyword
172
203
*`"causingExceptions"`: a (possibly empty) array of sub-exceptions. Each sub-exception is represented as a JSON object,
173
204
with the same structure as described in this listing. See more above about causing exceptions.
174
205
206
+
Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
207
+
be obtained using `#getCausingExceptions()` .
208
+
175
209
176
210
## Format validators
177
211
@@ -185,6 +219,12 @@ Starting from version `1.2.0` the library supports the [`"format"` keyword][draf
185
219
* ipv4
186
220
* ipv6
187
221
* uri
222
+
223
+
If you use the library in Draft 6 mode, then the followings are also supported:
224
+
225
+
* uri-reference
226
+
* uri-template
227
+
* json-pointer
188
228
189
229
The library also supports adding custom format validators. To use a custom validator basically you have to
0 commit comments