9
9
* [ Draft 4 or Draft 6?] ( #draft-4-or-draft-6 )
10
10
* [ Investigating failures] ( #investigating-failures )
11
11
* [ JSON report of the failures] ( #json-report-of-the-failures )
12
+ * [ Eary failure mode] ( #early-failure-mode )
13
+ * [ Default values] ( #default-values )
12
14
* [ Format validators] ( #format-validators )
13
15
* [ Example] ( #example )
14
16
* [ Resolution scopes] ( #resolution-scopes )
@@ -40,7 +42,7 @@ Add the JitPack repository and the dependency to your `pom.xml` as follows:
40
42
<dependency >
41
43
<groupId >com.github.everit-org.json-schema</groupId >
42
44
<artifactId >org.everit.json.schema</artifactId >
43
- <version >1.6.1 </version >
45
+ <version >1.7.0 </version >
44
46
</dependency >
45
47
...
46
48
<repositories >
@@ -191,6 +193,7 @@ This will print the following output:
191
193
#/rectangle/a: -5.0 is not higher or equal to 0
192
194
#/rectangle/b: expected type: Number, found: String
193
195
```
196
+
194
197
### JSON report of the failures
195
198
196
199
Since version ` 1.4.0 ` it is possible to print the ` ValidationException ` instances as
@@ -208,6 +211,43 @@ following keys:
208
211
Please take into account that the complete failure report is a * hierarchical tree structure* : sub-causes of a cause can
209
212
be obtained using ` #getCausingExceptions() ` .
210
213
214
+ ## Early failure mode
215
+
216
+ By default the validation error reporting in collecting mode (see the "Investigating failures" chapter). That is convenient for having a
217
+ detailed error report, but under some circumstances it is more appropriate to stop the validation when a failure is found without
218
+ checking the rest of the JSON document. To toggle this fast-failing validation mode
219
+ * you have to explicitly build a ` Validator ` instance for your schema instead of calling ` Schema#validate(input) `
220
+ * you have to call the ` failEarly() ` method of ` ValidatorBuilder `
221
+
222
+ Example:
223
+
224
+ ```
225
+ import org.everit.json.schema.Validator;
226
+ ...
227
+ Validator validator = Validator.builder()
228
+ .failEarly()
229
+ .build();
230
+ validator.performValidation(schema, input);
231
+ ```
232
+
233
+ _ Note: the ` Validator ` class is immutable and thread-safe, so you don't have to create a new one for each validation, it is enough
234
+ to configure it only once._
235
+
236
+
237
+ ## Default values
238
+
239
+ The JSON Schema specification defines the "default" keyword for denoting default values, though it doesn't explicitly state how it should
240
+ affect the validation process. By default this library doesn't set the default values, but if you need this feature, you can turn it on
241
+ by the ` SchemaLoaderBuilder#useDefaults(boolean) ` method, before loading the schema:
242
+
243
+ ```
244
+ Schema schema = SchemaLoader.builder()
245
+ .useDefaults(true)
246
+ .schemaJson(rawSchema)
247
+ .build()
248
+ .load().build();
249
+ schema.validate(input);
250
+ ```
211
251
212
252
## Format validators
213
253
0 commit comments