public final class Example8 extends ExampleBase
This example adds a custom format attribute named uuid
, which
checks whether a string instance is a valid UUID.
For this, you need to write an implementation of FormatAttribute
,
registering it in a Library
, and feed that library to a ValidationConfiguration
which you submit to the JsonSchemaFactory
.
Here, we choose to augment the draft v4 library, which we get hold of
using DraftV4Library.get()
; we thaw it, add the new attribute and
freeze it again. We also choose to make this new library the default by
using ValidationConfigurationBuilder.setDefaultLibrary(String, Library)
.
Note also that the schema has no $schema
defined; as a result, the
default library is used (it is not recommended to omit $schema
in your schemas, however).
Two sample files are given: the first (link) is valid, the other (link) isn't (the provided id
for the second array element is invalid).
Constructor and Description |
---|
Example8() |
Modifier and Type | Method and Description |
---|---|
static void |
main(String... args) |
loadResource, printReport
public static void main(String... args) throws IOException, com.github.fge.jsonschema.exceptions.ProcessingException
IOException
com.github.fge.jsonschema.exceptions.ProcessingException
Copyright © 2014. All Rights Reserved.