public final class JsonSchemaFactory extends Object
This class cannot be instantiated directly, you need to go through
its included JsonSchemaFactory.Builder to do that. This is so
that JsonSchema instances can be thread safe.
Unless you have several sets of keywords, 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.
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 FormatBundle |
formatBundle
Format bundle
|
private SchemaRegistry |
registry
Schema registry
|
| Modifier | Constructor and Description |
|---|---|
private |
JsonSchemaFactory(JsonSchemaFactory.Builder builder)
Constructor, private by design
|
| Modifier and Type | Method and Description |
|---|---|
JsonSchema |
createSchema(SchemaContainer container)
Create a schema from a container
|
private JsonSchema |
createSchema(SchemaContainer container,
JsonNode schema)
Create a
JsonSchema instance |
JsonSchema |
createSchema(SchemaContainer container,
String path)
Create a schema from a container, at a certain path
|
SchemaContainer |
getSchema(String str)
Get a schema container from a given URI
|
SchemaContainer |
getSchema(URI uri)
Get a schema container from a given URI
|
SchemaContainer |
registerSchema(JsonNode schema)
Register a schema
|
private final SchemaRegistry registry
private final JsonValidatorCache cache
private final FormatBundle formatBundle
private final EnumSet<ValidationFeature> features
private JsonSchemaFactory(JsonSchemaFactory.Builder builder)
builder - the builderJsonSchemaFactory.Builderpublic SchemaContainer registerSchema(JsonNode schema)
schema - the raw schemaJsonSchemapublic SchemaContainer getSchema(URI uri) throws JsonSchemaException
This is the other way to obtain a container (the other is
registerSchema(JsonNode)).
uri - the URIJsonSchemaException - cannot get schema from URI, or not a schemaSchemaRegistry.get(URI)public SchemaContainer getSchema(String str) throws JsonSchemaException
This calls getSchema(URI) and uses URI.create(String)
to build the URI
str - the URI as a stringJsonSchemaException - cannot get schema from URI, or not a schemaIllegalArgumentException - string is not a valid URIURI.create(String)public JsonSchema createSchema(SchemaContainer container)
This is one of the constructors you will use. The other is
createSchema(SchemaContainer, String).
container - the schema containerJsonSchema instancepublic JsonSchema createSchema(SchemaContainer container, String path)
For instance, if you register this schema:
{
"schema1": { ... },
"schema2": { ... }
}
then you can create a validator for schema1 using:
final JsonSchema schema = factory.create(container, "#/schema1");
The path can be a JsonPointer as above,
but also an id reference.
container - the schema containerpath - the pointer/id reference into the schemaJsonSchema instanceprivate JsonSchema createSchema(SchemaContainer container, JsonNode schema)
JsonSchema instancecontainer - the schema containerschema - the subschemaJsonSchema instanceCopyright © 2012. All Rights Reserved.