public final class JsonSchemaFactory extends Object
This class cannot be instantiated directly, you need to go through
its included JsonSchemaFactory.Builder to do that.
Unless you have several sets of custom keywords and/or format specifiers, you will probably only ever need one of these. It caches syntax validation results and keyword validators to speed up validation (quite a bit).
This class is thread safe and immutable.
JsonSchema| Modifier and Type | Class and Description |
|---|---|
static class |
JsonSchemaFactory.Builder
Builder class for a
JsonSchemaFactory |
| Modifier and Type | Field and Description |
|---|---|
private JsonValidatorCache |
cache
Validator cache
|
private EnumSet<ValidationFeature> |
features
List of supported features
|
private SchemaRegistry |
registry
Schema registry
|
| Modifier | Constructor and Description |
|---|---|
private |
JsonSchemaFactory(JsonSchemaFactory.Builder builder)
Constructor, private by design
|
| Modifier and Type | Method and Description |
|---|---|
private JsonSchema |
createSchema(SchemaContainer container,
JsonNode schema)
Create a
JsonSchema instance |
static JsonSchemaFactory |
defaultFactory()
Build a factory with all default settings
|
JsonSchema |
fromSchema(JsonNode schema)
Create a schema instance from a JSON Schema
|
JsonSchema |
fromSchema(JsonNode schema,
String path)
Create a schema instance from a JSON Schema, at a certain path
|
JsonSchema |
fromURI(String str)
Create a schema instance from a JSON Schema located at a given URI
|
JsonSchema |
fromURI(String str,
String path)
Create a schema instance from a JSON Schema located at a given URI and
at a given path
|
JsonSchema |
fromURI(URI uri)
Create a schema instance from a JSON Schema located at a given URI
|
JsonSchema |
fromURI(URI uri,
String path)
Create a schema instance from a JSON Schema located at a given URI, and
at a given path
|
private final SchemaRegistry registry
private final JsonValidatorCache cache
private final EnumSet<ValidationFeature> features
private JsonSchemaFactory(JsonSchemaFactory.Builder builder)
builder - the builderJsonSchemaFactory.Builderpublic static JsonSchemaFactory defaultFactory()
public JsonSchema fromSchema(JsonNode schema, String path)
For instance, if you submi this schema:
{
"schema1": { ... },
"schema2": { ... }
}
then you can create a validator for schema1 using:
final JsonSchema schema = factory.create(schema, "#/schema1");
The path can be a JsonPointer as above, but also an id
reference.
schema - the schemapath - the pointer/id reference into the schemaJsonSchema instanceJsonFragmentpublic JsonSchema fromSchema(JsonNode schema)
This calls fromSchema(JsonNode, String) with "" as
a path.
schema - the schemaJsonSchema instancepublic JsonSchema fromURI(URI uri, String path) throws JsonSchemaException
This allows you, for instance, to load a schema using HTTP. Or, in fact, any other URI scheme that is supported.
uri - the URIpath - the JSON Pointer/id reference into the downloaded schemaJsonSchema instanceJsonSchemaException - unable to get content from that URIURIManager,
SchemaRegistrypublic JsonSchema fromURI(URI uri) throws JsonSchemaException
uri - the URIJsonSchema instanceJsonSchemaException - unable to get content from that URIfromSchema(JsonNode, String)public JsonSchema fromURI(String str) throws JsonSchemaException
str - the URI as a stringJsonSchema instanceJsonSchemaException - unable to get content from that URIURI.create(String),
fromURI(URI, String)public JsonSchema fromURI(String str, String path) throws JsonSchemaException
str - the URI as a stringpath - the JSON Pointer/id reference into the downloaded schemaJsonSchema instanceJsonSchemaException - unable to get content from that URIURI.create(String),
fromURI(URI, String)private JsonSchema createSchema(SchemaContainer container, JsonNode schema)
JsonSchema instancecontainer - the schema containerschema - the subschemaJsonSchema instanceCopyright © 2012. All Rights Reserved.