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
- * [ Configuring the validation] ( #validator-config )
13
- * [ Eary failure mode] ( #validator-config-early-failure )
14
- * [ Default value support] ( #validator-config-default-support )
12
+ * [ Eary failure mode] ( #early-failure-mode )
13
+ * [ Default values] ( #default-values )
15
14
* [ Format validators] ( #format-validators )
16
15
* [ Example] ( #example )
17
16
* [ Resolution scopes] ( #resolution-scopes )
@@ -194,6 +193,7 @@ This will print the following output:
194
193
#/rectangle/a: -5.0 is not higher or equal to 0
195
194
#/rectangle/b: expected type: Number, found: String
196
195
```
196
+
197
197
### JSON report of the failures
198
198
199
199
Since version ` 1.4.0 ` it is possible to print the ` ValidationException ` instances as
@@ -211,43 +211,44 @@ following keys:
211
211
Please take into account that the complete failure report is a * hierarchical tree structure* : sub-causes of a cause can
212
212
be obtained using ` #getCausingExceptions() ` .
213
213
214
- ## Configuring the validation
214
+ ## Early failure mode
215
215
216
- If you call the ` Schema#validate(input) ` method then the validation will happen with a convenient mode which should meet the
217
- needs of most users for common scenarios. Though there can be cases where the default behaviour doesn't fit your needs. Then you can
218
- set some configuration values explicitly by manually creating a ` Validator ` instance and toggling some features in its builder, so
219
- instead of calling ` Schema.validate(input) ` , your code will look something like this:
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:
220
223
221
224
```
222
225
import org.everit.json.schema.Validator;
223
226
...
224
227
Validator validator = Validator.builder()
225
- /* configuration comes here */
228
+ .failEarly()
226
229
.build();
227
230
validator.performValidation(schema, input);
228
- ```
231
+ ```
229
232
230
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
231
234
to configure it only once._
232
235
233
- ### Early failure mode
234
236
235
- By default the validation error reporting in collecting mode (see the "Investigating failures" chapter). That is convenient for having a
236
- detailed error report, but under some circumstances it is more appropriate to stop the validation when a failure is found without
237
- checking the rest of the JSON document. To toggle this fast-failing validation mode you have to call the failEarly() method of
238
- ValidatorBuilder:
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:
239
242
240
243
```
241
- import org.everit.json. schema.Validator;
242
- ...
243
- Validator validator = Validator.builder( )
244
- .failEarly ()
245
- .build();
246
- validator.performValidation(schema, input);
244
+ Schema schema = SchemaLoader.builder()
245
+ .useDefaults(true)
246
+ .schemaJson(rawSchema )
247
+ .build ()
248
+ .load(). build();
249
+ schema.validate( input);
247
250
```
248
251
249
-
250
-
251
252
## Format validators
252
253
253
254
0 commit comments