com.github.fge.jsonschema.examples
Class Example8
java.lang.Object
com.github.fge.jsonschema.examples.Example8
public final class Example8
- extends Object
Eighth example: augmenting schemas with custom format attributes
link to source code
link to schema
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).
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Example8
public Example8()
main
public static void main(String... args)
throws IOException,
ProcessingException
- Throws:
IOException
ProcessingException