|
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 | 15 | * [Format validators](#format-validators)
|
13 | 16 | * [Example](#example)
|
14 | 17 | * [Resolution scopes](#resolution-scopes)
|
@@ -40,7 +43,7 @@ Add the JitPack repository and the dependency to your `pom.xml` as follows:
|
40 | 43 | <dependency>
|
41 | 44 | <groupId>com.github.everit-org.json-schema</groupId>
|
42 | 45 | <artifactId>org.everit.json.schema</artifactId>
|
43 |
| - <version>1.6.1</version> |
| 46 | + <version>1.7.0</version> |
44 | 47 | </dependency>
|
45 | 48 | ...
|
46 | 49 | <repositories>
|
@@ -208,6 +211,42 @@ 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 | +## Configuring the validation |
| 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: |
| 220 | + |
| 221 | +``` |
| 222 | +import org.everit.json.schema.Validator; |
| 223 | +... |
| 224 | +Validator validator = Validator.builder() |
| 225 | + /* configuration comes here */ |
| 226 | + .build(); |
| 227 | +validator.performValidation(schema, input); |
| 228 | +``` |
| 229 | + |
| 230 | +_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 | +to configure it only once._ |
| 232 | + |
| 233 | +### Early failure mode |
| 234 | + |
| 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: |
| 239 | + |
| 240 | +``` |
| 241 | +import org.everit.json.schema.Validator; |
| 242 | +... |
| 243 | +Validator validator = Validator.builder() |
| 244 | + .failEarly() |
| 245 | + .build(); |
| 246 | +validator.performValidation(schema, input); |
| 247 | +``` |
| 248 | + |
| 249 | + |
211 | 250 |
|
212 | 251 | ## Format validators
|
213 | 252 |
|
|
0 commit comments