Skip to content

Commit 3f7ef39

Browse files
committed
Merge branch 'readme-1.7.0'
2 parents e80884f + 1468c8b commit 3f7ef39

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* [Draft 4 or Draft 6?](#draft-4-or-draft-6)
1010
* [Investigating failures](#investigating-failures)
1111
* [JSON report of the failures](#json-report-of-the-failures)
12+
* [Eary failure mode](#early-failure-mode)
13+
* [Default values](#default-values)
1214
* [Format validators](#format-validators)
1315
* [Example](#example)
1416
* [Resolution scopes](#resolution-scopes)
@@ -40,7 +42,7 @@ Add the JitPack repository and the dependency to your `pom.xml` as follows:
4042
<dependency>
4143
<groupId>com.github.everit-org.json-schema</groupId>
4244
<artifactId>org.everit.json.schema</artifactId>
43-
<version>1.6.1</version>
45+
<version>1.7.0</version>
4446
</dependency>
4547
...
4648
<repositories>
@@ -191,6 +193,7 @@ This will print the following output:
191193
#/rectangle/a: -5.0 is not higher or equal to 0
192194
#/rectangle/b: expected type: Number, found: String
193195
```
196+
194197
### JSON report of the failures
195198

196199
Since version `1.4.0` it is possible to print the `ValidationException` instances as
@@ -208,6 +211,43 @@ following keys:
208211
Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
209212
be obtained using `#getCausingExceptions()` .
210213

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+
```
211251

212252
## Format validators
213253

0 commit comments

Comments
 (0)