public abstract class NumericKeywordValidator extends KeywordValidator
We separate validation in two: if both the keyword value and instance
value are integers which fit into a long
, we use that (for
performance reasons). If one of them doesn't, then we use BigDecimal
instead (for accuracy reasons).
This means that extending this validator will require you to implement two
methods: validateLong(ValidationReport, JsonNode)
and validateDecimal(ValidationReport, JsonNode)
.
You will note that these two methods take a JsonNode
as an
argument. Use the following methods to convert these to the appropriate
types:
Modifier and Type | Field and Description |
---|---|
protected JsonNode |
number
The keyword value
|
keyword
Modifier | Constructor and Description |
---|---|
protected |
NumericKeywordValidator(String keyword,
JsonNode schema)
Protected constructor
|
Modifier and Type | Method and Description |
---|---|
String |
toString() |
void |
validate(ValidationContext context,
ValidationReport report,
JsonNode instance)
Main validation method
|
protected abstract void |
validateDecimal(ValidationReport report,
JsonNode instance)
Method to be implemented by a numeric validator if either of the
keyword value or instance value do not fit into a
long |
protected abstract void |
validateLong(ValidationReport report,
JsonNode instance)
Method to be implemented by a numeric validator if both the keyword
value and instance value fit into a
long |
alwaysTrue, newMsg, validateInstance
protected final JsonNode number
protected abstract void validateLong(ValidationReport report, JsonNode instance)
long
report
- the validation reportinstance
- the instance to validateprotected abstract void validateDecimal(ValidationReport report, JsonNode instance)
long
report
- the validation reportinstance
- the instance to validatepublic final void validate(ValidationContext context, ValidationReport report, JsonNode instance)
This is where the test for long
is done on both the keyword
value and instance value. According to the result,
this method will then call either validateLong(ValidationReport,
JsonNode)
or validateDecimal(ValidationReport, JsonNode)
validate
in class KeywordValidator
context
- the contextreport
- the validation reportinstance
- the instance to validatepublic final String toString()
toString
in class KeywordValidator
Copyright © 2013. All Rights Reserved.