public final class JsonSchemaFactory extends Object
You can create a factory with all default settings using defaultFactory(). This is what you will do in the vast
majority of cases.
If you want to customize it, you need to go through JsonSchemaFactory.Builder.
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 | Method and Description |
|---|---|
JsonSchema |
createSchema(SchemaContainer container)
Deprecated.
use one of the
.from*() methods instead; scheduled
for removal in 1.3+ |
JsonSchema |
createSchema(SchemaContainer container,
String path)
Deprecated.
use
fromSchema(JsonNode, String) instead; scheduled
for removal in 1.3+ |
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
|
SchemaContainer |
getSchema(String str)
Deprecated.
use
fromURI(String) instead; scheduled for removal
in 1.3+ |
SchemaContainer |
getSchema(URI uri)
Deprecated.
use
fromURI(URI) instead; scheduled for removal
in 1.3+ |
SchemaContainer |
registerSchema(JsonNode schema)
Deprecated.
use
fromSchema(JsonNode) instead; scheduled for
removal in 1.3+ |
public static JsonSchemaFactory defaultFactory()
public JsonSchema fromSchema(JsonNode schema, String path)
For instance, if you submit 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 URIIllegalArgumentException - URI is invalidURI.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 URIIllegalArgumentException - URI is invalidURI.create(String),
fromURI(URI, String)@Deprecated public SchemaContainer registerSchema(JsonNode schema)
fromSchema(JsonNode) instead; scheduled for
removal in 1.3+schema - the raw schemaJsonSchema@Deprecated public SchemaContainer getSchema(URI uri) throws JsonSchemaException
fromURI(URI) instead; scheduled for removal
in 1.3+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)@Deprecated public SchemaContainer getSchema(String str) throws JsonSchemaException
fromURI(String) instead; scheduled for removal
in 1.3+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)@Deprecated public JsonSchema createSchema(SchemaContainer container)
.from*() methods instead; scheduled
for removal in 1.3+This is one of the constructors you will use. The other is
createSchema(SchemaContainer, String).
container - the schema containerJsonSchema instance@Deprecated public JsonSchema createSchema(SchemaContainer container, String path)
fromSchema(JsonNode, String) instead; scheduled
for removal in 1.3+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 instanceCopyright © 2012. All Rights Reserved.