| Interface | Description |
|---|---|
| SyntaxChecker |
Interface implemented by all syntax checkers
|
| Class | Description |
|---|---|
| ModZeroSyntaxChecker |
Syntax checker for the
divisibleBy keyword (draft v3) and multipleOf keyword (draft v4) |
| PositiveIntegerSyntaxChecker |
Syntax validator for keywords having a positive integer value as an argument
|
| SimpleSyntaxChecker |
Simple type-only syntax checker
|
| SyntaxValidator |
Schema syntax validator
|
The main class in this package is SyntaxValidator.
Syntax validation has a critically important role in the validation process. An invalid schema will always fail to validate a JSON instance.
For this implementation in particular, it also helps to ensure that the
KeywordValidator associated with
the schema keyword does not need to preoccupy about its arguments being
well-formed: it is the contract of syntax validation that a keyword validator
needs not preoccupy about this when it is instantiated.
Unlike keyword validators, syntax validators are not built by reflection. It is therefore your responsibility to instantiate it and only then register it.
Here is an example code for a hypothetic foo keyword which must
have a string as an argument, and this string must be at least 5 characters
long:
public final class SyntaxCheckerImpl
implements SyntaxChecker
{
@Override
public void checkSyntax(final Message.Builder msg,
final List<String> messages, final JsonNode schema)
{
final JsonNode node = schema.get(keyword);
if (!node.isTextual()) {
msg.setMessage("field is not a string");
messages.add(msg.build());
return;
}
if (node.textValue().length() >= 5)
return;
msg.setMessage("field has insufficient length")
.addInfo("required", 5)
.addInfo("found", node.textValue().length());
messages.add(msg.build());
}
}
For more information, see SyntaxChecker and Message.
Copyright © 2012. All Rights Reserved.