public abstract class FormatAttribute extends Object
The format keyword always takes a string as an argument, and this
string is called a "attribute". The draft defines attributes for recognizing
URIs, phone numbers, different date formats, and so on -- and even CSS 2.1
colors and styles (not supported).
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.
The spec allows for custom attributes to be added. This implementation supports it.
FormatBundle| Modifier | Constructor and Description |
|---|---|
protected |
FormatAttribute(NodeType first,
NodeType... other)
Protected constructor
|
| Modifier and Type | Method and Description |
|---|---|
abstract void |
checkValue(String fmt,
ValidationContext ctx,
ValidationReport report,
JsonNode value)
Abstract method implemented by all attributes
|
protected static Message.Builder |
newMsg(String fmt) |
void |
validate(String fmt,
ValidationContext ctx,
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, ValidationContext ctx, 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,
ValidationContext, 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 namectx - the validation contextreport - the validation reportvalue - the value to validatepublic abstract void checkValue(String fmt, ValidationContext ctx, ValidationReport report, JsonNode value)
It is only called if the value type is one expected by the
attribute, see validate(String, ValidationContext,
ValidationReport, JsonNode).
fmt - the format attribute namectx - the validation contextreport - the validation reportvalue - the value to validateprotected static Message.Builder newMsg(String fmt)
Copyright © 2012. All Rights Reserved.