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.
This kind of customization requires three steps:
KeywordRegistry;JsonSchemaFactory (via a
JsonSchemaFactory.Builder, as for all customizations) with a matching URI.Here, we choose to augment draft v3. We can fetch the URI and default
keyword registry for this version using KeywordRegistries.draftV3Core() and SchemaURIs.draftV3Core()
respectively. Note that the third argument to JsonSchemaFactory.Builder.addKeywordRegistry(JsonRef, KeywordRegistry, boolean) is true, since we want to make this schema the default.
Note also that the schema has no $schema defined; as a result, the
default schema is used (it is not recommended to omit $schema
in your own schemas).
Adding a custom format attribute is done by extending the FormatAttribute class.
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, printReportpublic static void main(String... args) throws IOException
IOExceptionCopyright © 2013. All Rights Reserved.