public abstract class KeywordValidator extends Object
In the processing order, a keyword validator is only called after the
schema has been deemed syntactically valid: this is why it is practically
a requirement that if you create a new validating keyword, you pair it with
a SyntaxChecker
. The constructor will be all the more simple as a
result.
A keyword only takes effect for a certain number of JSON instance types: if the instance to validate is not among these types, validation succeeds.
Two other abstract classes exist which you may want to extend instead of this one, depending on your needs:
NumericKeywordValidator
, for validating numeric instances;
PositiveIntegerKeywordValidator
, for keywords accepting only
a positive integer as an argument (to be paired with PositiveIntegerSyntaxChecker
).Modifier | Constructor and Description |
---|---|
protected |
KeywordValidator(String keyword,
NodeType... types)
Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
alwaysTrue() |
protected Message.Builder |
newMsg()
Create a new validation message template
|
abstract String |
toString() |
protected abstract void |
validate(ValidationContext context,
ValidationReport report,
JsonNode instance)
Method which all keyword validators must implement
|
void |
validateInstance(ValidationContext context,
ValidationReport report,
JsonNode instance)
Main validation function
|
protected final String keyword
public final void validateInstance(ValidationContext context, ValidationReport report, JsonNode instance)
Its only role is to check whether the instance type is recognized
by this keyword. If so, it calls validate(ValidationContext,
ValidationReport, JsonNode)
.
context
- the contextreport
- the validation reportinstance
- the instance to validateprotected abstract void validate(ValidationContext context, ValidationReport report, JsonNode instance)
context
- the contextreport
- the validation reportinstance
- the instance to validateprotected final Message.Builder newMsg()
Use this class when you want to report errors. It will have filled
the message with the correct domain (Domain.VALIDATION
)
and keyword.
Message
public boolean alwaysTrue()
Copyright © 2013. All Rights Reserved.