Class JsonSchemaFactory
JsonSchema
instances. The factory should be
typically be created using getInstance(VersionFlag, Consumer)
and
should be cached for performance.
JsonSchemaFactory instances are thread-safe provided its configuration is not modified.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonSchemaFactory.Builder
builder()
Builder without keywords or formats.static JsonSchemaFactory.Builder
builder
(JsonSchemaFactory blueprint) Builder from an existingJsonSchemaFactory
.static JsonSchemaVersion
checkVersion
(SpecVersion.VersionFlag versionFlag) Gets the json schema version to get the meta schema.create
(ValidationContext validationContext, SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema) protected SchemaValidatorsConfig
Creates a schema validators config.protected ValidationContext
createValidationContext
(com.fasterxml.jackson.databind.JsonNode schemaNode, SchemaValidatorsConfig config) static JsonSchemaFactory
getInstance
(SpecVersion.VersionFlag versionFlag) Creates a factory with a default schema dialect.static JsonSchemaFactory
getInstance
(SpecVersion.VersionFlag versionFlag, Consumer<JsonSchemaFactory.Builder> customizer) Creates a factory with a default schema dialect.protected JsonSchema
getMappedSchema
(SchemaLocation schemaUri, SchemaValidatorsConfig config) getMetaSchema
(String iri, SchemaValidatorsConfig config) Gets the meta-schema that is available to the factory.getSchema
(com.fasterxml.jackson.databind.JsonNode jsonNode) Gets the schema.getSchema
(com.fasterxml.jackson.databind.JsonNode jsonNode, SchemaValidatorsConfig config) Gets the schema.getSchema
(SchemaLocation schemaUri) Gets the schema.getSchema
(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode) Gets the schema.getSchema
(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode, SchemaValidatorsConfig config) Gets the schema.getSchema
(SchemaLocation schemaUri, SchemaValidatorsConfig config) Gets the schema.getSchema
(InputStream schemaStream) Gets the schema.getSchema
(InputStream schemaStream, InputFormat inputFormat, SchemaValidatorsConfig config) Gets the schema.getSchema
(InputStream schemaStream, SchemaValidatorsConfig config) Gets the schema.Gets the schema.getSchema
(String schema, InputFormat inputFormat) Gets the schema.getSchema
(String schema, InputFormat inputFormat, SchemaValidatorsConfig config) Gets the schema.getSchema
(String schema, SchemaValidatorsConfig config) Gets the schema.Gets the schema.Gets the schema.getSchema
(URI schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode, SchemaValidatorsConfig config) Gets the schema.protected SchemaLocation
getSchemaLocation
(SchemaLocation schemaLocation) Gets the base IRI from the schema retrieval IRI if present otherwise return one with a null base IRI.protected JsonMetaSchema
loadMetaSchema
(String iri, SchemaValidatorsConfig config) Loads the meta-schema from the configured meta-schema factory.protected JsonSchema
loadSchema
(SchemaLocation schemaUri, SchemaValidatorsConfig config) Loads the schema.protected JsonSchema
newJsonSchema
(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode schemaNode, SchemaValidatorsConfig config) Creates a json schema from initial input.protected static String
Normalizes the standard JSON schema dialects.
-
Method Details
-
getSchemaLoader
-
builder
Builder without keywords or formats. Typicallybuilder(JsonSchemaFactory)
is what is required.- Returns:
- a builder instance without any keywords or formats - usually not what one needs.
-
getInstance
Creates a factory with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.- Parameters:
versionFlag
- the default dialect- Returns:
- the factory
-
getInstance
public static JsonSchemaFactory getInstance(SpecVersion.VersionFlag versionFlag, Consumer<JsonSchemaFactory.Builder> customizer) Creates a factory with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.- Parameters:
versionFlag
- the default dialectcustomizer
- to customize the factory- Returns:
- the factory
-
checkVersion
Gets the json schema version to get the meta schema.This throws an
IllegalArgumentException
for an unsupported value.- Parameters:
versionFlag
- the schema dialect- Returns:
- the version
-
builder
Builder from an existingJsonSchemaFactory
.JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909));
- Parameters:
blueprint
- the existing factory- Returns:
- the builder
-
newJsonSchema
protected JsonSchema newJsonSchema(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode schemaNode, SchemaValidatorsConfig config) Creates a json schema from initial input.- Parameters:
schemaUri
- the schema locationschemaNode
- the schema data nodeconfig
- the config to use- Returns:
- the schema
-
create
public JsonSchema create(ValidationContext validationContext, SchemaLocation schemaLocation, JsonNodePath evaluationPath, com.fasterxml.jackson.databind.JsonNode schemaNode, JsonSchema parentSchema) -
getSchemaLocation
Gets the base IRI from the schema retrieval IRI if present otherwise return one with a null base IRI.Note that the resolving of the $id or id in the schema node will take place in the JsonSchema constructor.
- Parameters:
schemaLocation
- the schema retrieval uri- Returns:
- the schema location
-
createValidationContext
protected ValidationContext createValidationContext(com.fasterxml.jackson.databind.JsonNode schemaNode, SchemaValidatorsConfig config) -
getMetaSchema
Gets the meta-schema that is available to the factory.- Parameters:
iri
- the IRI of the meta-schemaconfig
- the schema validators config- Returns:
- the meta-schema
-
loadMetaSchema
Loads the meta-schema from the configured meta-schema factory.- Parameters:
iri
- the IRI of the meta-schemaconfig
- the schema validators config- Returns:
- the meta-schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schema
- the schema data as a stringconfig
- the config- Returns:
- the schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schema
- the schema data as a stringinputFormat
- input formatconfig
- the config- Returns:
- the schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schema
- the schema data as a string- Returns:
- the schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schema
- the schema data as a stringinputFormat
- input format- Returns:
- the schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schemaStream
- the input stream with the schema dataconfig
- the config- Returns:
- the schema
-
getSchema
public JsonSchema getSchema(InputStream schemaStream, InputFormat inputFormat, SchemaValidatorsConfig config) Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schemaStream
- the input stream with the schema datainputFormat
- input formatconfig
- the config- Returns:
- the schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
- Parameters:
schemaStream
- the input stream with the schema data- Returns:
- the schema
-
getSchema
Gets the schema.- Parameters:
schemaUri
- the absolute IRI of the schema which can map to the retrieval IRI.config
- the config- Returns:
- the schema
-
loadSchema
Loads the schema.- Parameters:
schemaUri
- the absolute IRI of the schema which can map to the retrieval IRI.config
- the config- Returns:
- the schema
-
createSchemaValidatorsConfig
Creates a schema validators config.- Returns:
- the schema validators config
-
getMappedSchema
-
getSchema
Gets the schema.- Parameters:
schemaUri
- the absolute IRI of the schema which can map to the retrieval IRI.- Returns:
- the schema
-
getSchema
public JsonSchema getSchema(URI schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode, SchemaValidatorsConfig config) Gets the schema.- Parameters:
schemaUri
- the absolute IRI of the schema which can map to the retrieval IRI.jsonNode
- the nodeconfig
- the config- Returns:
- the schema
-
getSchema
Gets the schema.- Parameters:
schemaUri
- the absolute IRI of the schema which can map to the retrieval IRI.jsonNode
- the node- Returns:
- the schema
-
getSchema
Gets the schema.- Parameters:
schemaUri
- the absolute IRI of the schema which can map to the retrieval IRI.- Returns:
- the schema
-
getSchema
public JsonSchema getSchema(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode, SchemaValidatorsConfig config) Gets the schema.- Parameters:
schemaUri
- the base absolute IRIjsonNode
- the nodeconfig
- the config- Returns:
- the schema
-
getSchema
public JsonSchema getSchema(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode) Gets the schema.- Parameters:
schemaUri
- the base absolute IRIjsonNode
- the node- Returns:
- the schema
-
getSchema
public JsonSchema getSchema(com.fasterxml.jackson.databind.JsonNode jsonNode, SchemaValidatorsConfig config) Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
Prefer
getSchema(SchemaLocation, JsonNode, SchemaValidatorsConfig)
instead to ensure the base IRI if no id is present.- Parameters:
jsonNode
- the nodeconfig
- the config- Returns:
- the schema
-
getSchema
Gets the schema.Using this is not recommended as there is potentially no base IRI for resolving references to the absolute IRI.
Prefer
getSchema(SchemaLocation, JsonNode)
instead to ensure the base IRI if no id is present.- Parameters:
jsonNode
- the node- Returns:
- the schema
-
normalizeMetaSchemaUri
Normalizes the standard JSON schema dialects.This should not normalize any other unrecognized dialects.
- Parameters:
id
- the $schema identifier- Returns:
- the normalized uri
-