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 |
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)
Specialized constructor for validation internals
|
JsonSchema |
createSchema(SchemaContainer container,
String path)
Create a schema from a container, at a certain path
|
SchemaContainer |
getSchema(URI uri)
Get a schema container from a given URI
|
JsonValidatorCache |
getValidatorCache() |
SchemaContainer |
registerSchema(JsonNode schema)
Register a schema
|
private final SchemaRegistry registry
private final JsonValidatorCache cache
private JsonSchemaFactory(JsonSchemaFactory.Builder builder)
builder - the builderJsonSchemaFactory.Builderpublic SchemaContainer registerSchema(JsonNode schema) throws JsonSchemaException
schema - the raw schemaJsonSchemaJsonSchemaException - illegal schemapublic 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 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)
You should not use it in theory. I can dream ;)
container - the schema containerschema - the subschemaJsonSchema instancepublic JsonValidatorCache getValidatorCache()
Copyright © 2012. All Rights Reserved.