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:
MetaSchema.Builder
;JsonSchemaFactory
(via a JsonSchemaFactory.Builder
, as for all
customizations).Here, we choose to augment the draft v3 core schema. We can base our new
meta-schema by using MetaSchema.basedOn(BuiltinSchemas)
with
BuiltinSchemas.DRAFTV3_CORE
as an argument, add our format attribute
to it, build it and add it to our factory, using (MetaSchema, boolean)
. Note that the
second argument is true
so that our new meta-schema is regarded as
the default.
Note also that the schema has no $schema
defined; as a result, the
default meta-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, printReport
public static void main(String... args) throws IOException
IOException
Copyright © 2013. All Rights Reserved.