|
9 | 9 | * [Draft 4 or Draft 6 or Draft 7?](#draft-4-or-draft-6-or-draft-7)
|
10 | 10 | * [Investigating failures](#investigating-failures)
|
11 | 11 | * [JSON report of the failures](#json-report-of-the-failures)
|
| 12 | +* [ValidationListeners - Tracking the validation process](#validation-listeners-tracking-the-validation-process) |
12 | 13 | * [Eary failure mode](#early-failure-mode)
|
13 | 14 | * [Default values](#default-values)
|
14 | 15 | * [RegExp implementations](#regexp-implementations)
|
@@ -219,7 +220,40 @@ following keys:
|
219 | 220 | with the same structure as described in this listing. See more above about causing exceptions.
|
220 | 221 |
|
221 | 222 | Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
|
222 |
| -be obtained using `#getCausingExceptions()` . |
| 223 | +be obtained using `#getCausingExceptions()` . |
| 224 | + |
| 225 | +## ValidationListeners - Tracking the validation process |
| 226 | + |
| 227 | +`ValidationListener`s can serve the purpose of resolving ambiguity about _how_ does an instance JSON match (or does not match) |
| 228 | +against a schema. You can attach a `ValidationListener` implementation to the validator to receive event notifications about intermediate |
| 229 | +success/failure results. |
| 230 | + |
| 231 | +Example: |
| 232 | + |
| 233 | +```java |
| 234 | +import org.everit.json.schema.Validator; |
| 235 | +... |
| 236 | +Validator validator = Validator.builder() |
| 237 | + .withListener(new YourValidationListenerImplementation()) |
| 238 | + .build(); |
| 239 | +validator.performValidation(schema, input); |
| 240 | +``` |
| 241 | + |
| 242 | +The currently supported events: |
| 243 | + |
| 244 | + * a `"$ref"` reference being resolved |
| 245 | + * a subschema under an `"allOf"` / `"anyOf"` / `"oneOf"` schema matching |
| 246 | + * a subschema under an `"allOf"` / `"anyOf"` / `"oneOf"` schema failing to match |
| 247 | + * an `"if"` schema matching |
| 248 | + * an `"if"` schema failing to match |
| 249 | + * an `"then"` schema matching |
| 250 | + * an `"then"` schema failing to match |
| 251 | + * an `"else"` schema matching |
| 252 | + * an `"else"` schema failing to match |
| 253 | + |
| 254 | + |
| 255 | +See the javadoc of the `org.everit.json.schema.event.ValidationListener` interface for more details. The particular event classes also have |
| 256 | +proper `#toJSON()` and `#toString()` implementations so you can print them in an easily parse-able format. |
223 | 257 |
|
224 | 258 | ## Early failure mode
|
225 | 259 |
|
|
0 commit comments