Class SchemaRegistry
Schema instances.
This can be created with withDefaultDialect(Version) or withDialect(Dialect).
The registry should be cached for performance.
A different registry should be used when loading unrelated schemas.
SchemaRegistry instances are thread-safe provided its configuration is not modified.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SchemaRegistry.Builderbuilder()Builder without keywords or formats.static SchemaRegistry.Builderbuilder(SchemaRegistry blueprint) Builder from an existingSchemaRegistry.create(SchemaContext schemaContext, SchemaLocation schemaLocation, com.fasterxml.jackson.databind.JsonNode schemaNode, Schema parentSchema) protected SchemaContextcreateSchemaContext(com.fasterxml.jackson.databind.JsonNode schemaNode) getDialect(String dialectId) Gets the dialect that is available to the registry.protected SchemagetMappedSchema(SchemaLocation schemaUri) getSchema(com.fasterxml.jackson.databind.JsonNode jsonNode) Gets the schema.getSchema(SchemaLocation schemaUri) Gets the schema.getSchema(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode jsonNode) Gets the schema.getSchema(SchemaLocation schemaUri, InputStream schemaStream, InputFormat inputFormat) Gets the schema.getSchema(SchemaLocation schemaUri, String schema, InputFormat inputFormat) Gets the schema.getSchema(InputStream schemaStream) Gets the schema.getSchema(InputStream schemaStream, InputFormat inputFormat) Gets the schema.Gets the schema.getSchema(String schema, InputFormat inputFormat) Gets the schema.Gets the schema loader.protected SchemaLocationgetSchemaLocation(SchemaLocation schemaLocation) Gets the base IRI from the schema retrieval IRI if present otherwise return one with a null base IRI.Gets the schema registry config.loadSchema(SchemaLocation schemaUri) Loads the schema.protected SchemanewSchema(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode schemaNode) Creates a schema from initial input.protected static StringNormalizes the standard JSON schema dialects.static SchemaRegistrywithDefaultDialect(Dialect dialect) Creates a new schema registry with a default schema dialect.static SchemaRegistrywithDefaultDialect(Dialect dialect, Consumer<SchemaRegistry.Builder> customizer) Creates a new schema registry with a default schema dialect.static SchemaRegistrywithDefaultDialect(SpecificationVersion specificationVersion) Creates a new schema registry with a default schema dialect.static SchemaRegistrywithDefaultDialect(SpecificationVersion specificationVersion, Consumer<SchemaRegistry.Builder> customizer) Creates a new schema registry with a default schema dialect.static SchemaRegistrywithDefaultDialectId(String dialectId, Consumer<SchemaRegistry.Builder> customizer) Creates a new schema registry with a default schema dialect.static SchemaRegistrywithDialect(Dialect dialect) Gets a new schema registry that supports a specific dialect only.static SchemaRegistrywithDialect(Dialect dialect, Consumer<SchemaRegistry.Builder> customizer) Gets a new schema registry that supports a list of specific dialects only.static SchemaRegistrywithDialects(List<Dialect> dialects) Gets a new schema registry that supports a list of specific dialects only.static SchemaRegistrywithDialects(List<Dialect> dialects, Consumer<SchemaRegistry.Builder> customizer) Gets a new schema registry that supports a specific dialect only.
-
Method Details
-
builder
Builder without keywords or formats.Typically
builder(SchemaRegistry)orwithDefaultDialect(SpecificationVersion)orwithDialect(Dialect)would be used instead.- Returns:
- a builder instance without any keywords or formats - usually not what one needs.
-
withDefaultDialect
Creates a new schema registry with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.This uses a dialect registry that contains all the supported standard specification dialects, Draft 4, Draft 6, Draft 7, Draft 2019-09 and Draft 2020-12.
- Parameters:
specificationVersion- the default dialect id corresponding to the specification version used when the schema does not specify the $schema keyword- Returns:
- the factory
-
withDefaultDialect
public static SchemaRegistry withDefaultDialect(SpecificationVersion specificationVersion, Consumer<SchemaRegistry.Builder> customizer) Creates a new schema registry with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.This uses a dialect registry that contains all the supported standard specification dialects, Draft 4, Draft 6, Draft 7, Draft 2019-09 and Draft 2020-12.
- Parameters:
specificationVersion- the default dialect id corresponding to the specification version used when the schema does not specify the $schema keywordcustomizer- to customize the registry- Returns:
- the factory
-
withDefaultDialectId
public static SchemaRegistry withDefaultDialectId(String dialectId, Consumer<SchemaRegistry.Builder> customizer) Creates a new schema registry with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.This uses a dialect registry that contains all the supported standard specification dialects, Draft 4, Draft 6, Draft 7, Draft 2019-09 and Draft 2020-12.
- Parameters:
dialectId- the default dialect id used when the schema does not specify the $schema keywordcustomizer- to customize the registry- Returns:
- the factory
-
withDefaultDialect
Creates a new schema registry with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.This uses a dialect registry that contains all the supported standard specification dialects, Draft 4, Draft 6, Draft 7, Draft 2019-09 and Draft 2020-12.
- Parameters:
dialect- the default dialect used when the schema does not specify the $schema keyword- Returns:
- the factory
-
withDefaultDialect
public static SchemaRegistry withDefaultDialect(Dialect dialect, Consumer<SchemaRegistry.Builder> customizer) Creates a new schema registry with a default schema dialect. The schema dialect will only be used if the input does not specify a $schema.This uses a dialect registry that contains all the supported standard specification dialects, Draft 4, Draft 6, Draft 7, Draft 2019-09 and Draft 2020-12.
- Parameters:
dialect- the default dialect used when the schema does not specify the $schema keywordcustomizer- to customize the registry- Returns:
- the factory
-
withDialect
Gets a new schema registry that supports a specific dialect only.Schemas that do not specify dialect using $schema will use the dialect.
This uses a dialect registry that only contains this dialect and will throw an exception for unknown dialects.
- Parameters:
dialect- the dialect- Returns:
- the schema registry
-
withDialect
public static SchemaRegistry withDialect(Dialect dialect, Consumer<SchemaRegistry.Builder> customizer) Gets a new schema registry that supports a list of specific dialects only.Schemas that do not specify dialect using $schema will use the first dialect on the list.
This uses a dialect registry that only contains the list of dialects and will throw an exception for unknown dialects.
- Parameters:
dialect- the dialectcustomizer- to customize the registry- Returns:
- the schema registry
-
withDialects
Gets a new schema registry that supports a list of specific dialects only.Schemas that do not specify dialect using $schema will use the first dialect on the list.
This uses a dialect registry that only contains the list of dialects and will throw an exception for unknown dialects.
- Parameters:
dialects- the dialects with the first being the default dialect- Returns:
- the schema registry
-
withDialects
public static SchemaRegistry withDialects(List<Dialect> dialects, Consumer<SchemaRegistry.Builder> customizer) Gets a new schema registry that supports a specific dialect only.Schemas that do not specify dialect using $schema will use the dialect.
This uses a dialect registry that only contains this dialect and will throw an exception for unknown dialects.
- Parameters:
dialects- the dialects with the first being the default dialectcustomizer- to customize the registry- Returns:
- the schema registry
-
builder
Builder from an existingSchemaRegistry.SchemaRegistry.builder(SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2019_09));- Parameters:
blueprint- the existing factory- Returns:
- the builder
-
getSchemaLoader
Gets the schema loader.- Returns:
- the schema loader
-
newSchema
protected Schema newSchema(SchemaLocation schemaUri, com.fasterxml.jackson.databind.JsonNode schemaNode) Creates a schema from initial input.- Parameters:
schemaUri- the schema locationschemaNode- the schema data node- Returns:
- the schema
-
create
public Schema create(SchemaContext schemaContext, SchemaLocation schemaLocation, com.fasterxml.jackson.databind.JsonNode schemaNode, Schema 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 Schema constructor.
- Parameters:
schemaLocation- the schema retrieval uri- Returns:
- the schema location
-
createSchemaContext
-
getDialect
Gets the dialect that is available to the registry.- Parameters:
dialectId- the IRI of the meta-schema- 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 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 data- 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 datainputFormat- input format- 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
Gets the schema.- Parameters:
schemaUri- the base absolute IRIjsonNode- the node- Returns:
- the schema
-
getSchema
Gets the schema.- Parameters:
schemaUri- the base absolute IRIschema- the input schema datainputFormat- input format- Returns:
- the schema
-
getSchema
public Schema getSchema(SchemaLocation schemaUri, InputStream schemaStream, InputFormat inputFormat) Gets the schema.- Parameters:
schemaUri- the base absolute IRIschemaStream- the input schema datainputFormat- 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.
Prefer
getSchema(SchemaLocation, JsonNode)instead to ensure the base IRI if no id is present.- Parameters:
jsonNode- the node- Returns:
- the schema
-
loadSchema
Loads the schema.- Parameters:
schemaUri- the absolute IRI of the schema which can map to the retrieval IRI.- Returns:
- the schema
-
getMappedSchema
-
getSchemaRegistryConfig
Gets the schema registry config.- Returns:
- the schema registry config
-
normalizeDialectId
Normalizes the standard JSON schema dialects.This should not normalize any other unrecognized dialects.
- Parameters:
id- the $schema identifier- Returns:
- the normalized uri
-