public abstract class FormatAttribute extends Object
The format
keyword always takes a string as an argument, and this
string is called a "attribute". See FormatAttributes
for the list of
supported attributes.
One important thing to remember is that a attribute will only validate a
given subset of JSON instance types (for instance, uri
only validates
string instances). In the event that the instane type is not of the
validated types, validation succeeds.
JSON Schema specifications allow for custom attributes to be added. This implementation supports it.
Final note: even though you may register format attributes to validate container instances, drafts also explicitly says that you should not do so.
KeywordRegistry
Modifier | Constructor and Description |
---|---|
protected |
FormatAttribute(NodeType first,
NodeType... other)
Protected constructor
|
Modifier and Type | Method and Description |
---|---|
abstract void |
checkValue(String fmt,
ValidationReport report,
JsonNode value)
Abstract method implemented by all attributes
|
protected static Message.Builder |
newMsg(String fmt) |
void |
validate(String fmt,
ValidationReport report,
JsonNode value)
Main validation function
|
protected FormatAttribute(NodeType first, NodeType... other)
Its arguments are the node types recognized by the attribute. Only
one attribute recognizes more than one type: utc-millisec
(it
can validate both numbers and integers).
first
- first typeother
- other types, if anypublic final void validate(String fmt, ValidationReport report, JsonNode value)
This function only checks whether the value is of a type recognized
by this attribute. If so, it calls checkValue(String,
ValidationReport, JsonNode)
.
The message template passed as an argument will have been pre-filled
with the keyword (format
), the attribute name and the domain
(Domain.VALIDATION
).
fmt
- the format attribute namereport
- the validation reportvalue
- the value to validatepublic abstract void checkValue(String fmt, ValidationReport report, JsonNode value)
It is only called if the value type is one expected by the
attribute, see validate(String, ValidationReport, JsonNode)
.
fmt
- the format attribute namereport
- the validation reportvalue
- the value to validateprotected static Message.Builder newMsg(String fmt)
Copyright © 2013. All Rights Reserved.