-
Notifications
You must be signed in to change notification settings - Fork 399
What's new (1.x)
2.x will see major changes. This is the last 1.x version.
This is the only change in 1.6.x. In all previous 1.x versions, syntax validation was only done on demand; with this version, a schema is fully validated prior to being used.
There is now a dedicated package for examples: see here. This tells the whole story about the user API and developer API. Please refer to the examples for code usage.
The most important changes are summarized below.
This project now required Jackson 2.1.1 or better. This is due to a misbehaviour being fixed with regards to decimal numeric instances using BigDecimal
(1.00
and 1.0
were not considered equal).
The implementation now honors $schema
when it is present in a JSON Schema. Draft v4 core schema keywords and draft v3 hyper schema keywords are now supported as well (although only syntax validation for the latter, since they have no role in instance validation).
Also note that the default (if $schema
is not present, or if the URI is unknown) it to validate the schema syntax against draft v3 hyper schema (previously, it was draft v3 core schema).
1.2.x got rid of "less used" format attributes in draft v3. They are now here again (except for color
and style
).
A new format attribute, media-type
, is also present in order to be able to successfully validate link description objects in draft v3 hyper schema.
In 1.2.x, 1.0
and 1
were not considered equal, which is a violation of the JSON Schema specification. Worse, even 1.00
and 1.0
were not considered equal (due to a bug in Jackson, see above).
This release fixes this behaviour while retaining the type (1.0
is still a number, but is not an integer; 1
, 1.0
and 1.00
are all equal).
For instance, this kind of addressing will work:
{
"type": "object",
"additionalProperties": { "$ref": "#oneProperty" },
"subSchema": {
"id": "#oneProperty",
"keywords": "here"
}
}
However, for security reasons, this is not the default.
-
Two new keywords have been added, "backported" from draft v4:
minProperties
andmaxProperties
. These enforce respectively the minimum and maximum number of members in an object instance. -
You can now use a JAR URL (always
/
-terminated, of course) as a URI namespace (this didn't work with 1.0.x). -
$ref
resolution failures are now always fatal -- even indisallow
(prior to that,disallow
hid that fact). Also, processing stops immediately in such an event, and the only message you have in the report is the ref resolution failure message (along with the URI which triggered it, of course!). -
JsonSchemaFactory
is now easier to use. First, you can now build a factory with default settings with:
final JsonSchemaFactory factory = JsonSchemaFactory.defaultFactory();
Second, instead of creating a SchemaContainer
and only then a JsonSchema
, you can now create a JsonSchema
directly. Ie, instead of doing:
final SchemaContainer container = factory.registerSchema(node);
final JsonSchema schema = factory.createSchema(container);
you now do:
final JsonSchema schema = factory.fromSchema(node);
Some other methods have been created for convenience as well. See the Javadoc for more details.
-
JsonLoader
has gained the ability to load JSON data from aString
. -
ValidationReport
has gained a new method to retrieve messages as a JSON array (in 1.0.x, only a JSON object representation was available). Before:
// Retrieve the list of messages as a JSON object
final JsonNode object = report.asJsonNode();
Now:
// As object
final JsonNode object = report.asJsonObject();
// As array
final JsonNode array = report.asJsonArray();
- More speed improvements, but you will really only see them if you validate a LOT of data (which I do).
There is quite a lot to say here...
-
Three classes have been renamed:
-
ValidationMessage
->Message
; -
ValidationDomain
->Domain
; -
FormatSpecifier
->FormatAttribute
.
-
-
To create a validation message, you now have to use
Domain
's.newMessage()
method.
Before:
final ValidationMessage.Builder builder
= new ValidationMessage.Builder(ValidationDomain.SYNTAX).etc().etc();
Now:
final Message.Builder builder = Domain.SYNTAX.newMessage().etc().etc();
- The way to create a new schema keyword (provided you already have the relevant
SyntaxChecker
andKeywordValidator
, of course) has changed.
Before:
final Keyword keyword = Keyword.Builder.forKeyword("foo").etc().etc().build();
Now:
final Keyword keyword = Keyword.withName("foo").etc().etc().build();