Skip to content

Commit a0b1145

Browse files
committed
readme for ValidationListener
1 parent 325af6b commit a0b1145

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Draft 4 or Draft 6 or Draft 7?](#draft-4-or-draft-6-or-draft-7)
1010
* [Investigating failures](#investigating-failures)
1111
* [JSON report of the failures](#json-report-of-the-failures)
12+
* [ValidationListeners - Tracking the validation process](#validation-listeners-tracking-the-validation-process)
1213
* [Eary failure mode](#early-failure-mode)
1314
* [Default values](#default-values)
1415
* [RegExp implementations](#regexp-implementations)
@@ -219,7 +220,40 @@ following keys:
219220
with the same structure as described in this listing. See more above about causing exceptions.
220221

221222
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.
223257

224258
## Early failure mode
225259

0 commit comments

Comments
 (0)