Interface MongoJsonSchema
public interface MongoJsonSchema
Interface defining MongoDB-specific JSON schema object. New objects can be built with
builder()
, for
example:
MongoJsonSchema schema = MongoJsonSchema.builder().required("firstname", "lastname") .properties(string("firstname").possibleValues("luke", "han"), object("address").properties(string("postCode").minLength(4).maxLength(5)) ).build();resulting in the following schema:
{ "type": "object", "required": [ "firstname", "lastname" ], "properties": { "firstname": { "type": "string", "enum": [ "luke", "han" ], }, "address": { "type": "object", "properties": { "postCode": { "type": "string", "minLength": 4, "maxLength": 5 } } } } }
- Since:
- 2.1
- Author:
- Christoph Strobl, Mark Paluch
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A resolution function that is called on conflicting paths when trying to merge properties with different values into a single value.static class
MongoJsonSchema.MongoJsonSchemaBuilder
provides a fluent API for defining aMongoJsonSchema
. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Obtain a newMongoJsonSchema.MongoJsonSchemaBuilder
to fluently define the schema.static MongoJsonSchema
merge
(MongoJsonSchema... sources) Create a newMongoJsonSchema
merging properties from the given sources.static MongoJsonSchema
merge
(MongoJsonSchema.ConflictResolutionFunction mergeFunction, MongoJsonSchema... sources) Create a newMongoJsonSchema
merging properties from the given sources.default MongoJsonSchema
mergeWith
(Collection<MongoJsonSchema> sources) Create a newMongoJsonSchema
merging properties from the given sources.default MongoJsonSchema
mergeWith
(Collection<MongoJsonSchema> sources, MongoJsonSchema.ConflictResolutionFunction conflictResolutionFunction) Create a newMongoJsonSchema
merging properties from the given sources.default MongoJsonSchema
mergeWith
(MongoJsonSchema... sources) Create a newMongoJsonSchema
merging properties from the given sources.static MongoJsonSchema
of
(org.bson.Document document) Create a newMongoJsonSchema
for a given rootDocument
containing the schema definition.static MongoJsonSchema
of
(JsonSchemaObject root) Create a newMongoJsonSchema
for a given root object.org.bson.Document
Create theDocument
defining the schema.default org.bson.Document
-
Method Details
-
toDocument
default org.bson.Document toDocument()Create the$jsonSchema
Document
containing the specifiedschemaDocument()
.
Property and field names need to be mapped to the domain type ones by running theDocument
through aJsonSchemaMapper
to apply field name customization.- Returns:
- never null.
-
schemaDocument
org.bson.Document schemaDocument()Create theDocument
defining the schema.
Property and field names need to be mapped to the domain type property by running theDocument
through aJsonSchemaMapper
to apply field name customization.- Returns:
- never null.
- Since:
- 3.3
-
of
Create a newMongoJsonSchema
for a given root object.- Parameters:
root
- must not be null.- Returns:
- new instance of
MongoJsonSchema
.
-
of
Create a newMongoJsonSchema
for a given rootDocument
containing the schema definition.- Parameters:
document
- must not be null.- Returns:
- new instance of
MongoJsonSchema
.
-
merge
Create a newMongoJsonSchema
merging properties from the given sources.- Parameters:
sources
- must not be null.- Returns:
- new instance of
MongoJsonSchema
. - Since:
- 3.4
-
merge
static MongoJsonSchema merge(MongoJsonSchema.ConflictResolutionFunction mergeFunction, MongoJsonSchema... sources) Create a newMongoJsonSchema
merging properties from the given sources.- Parameters:
sources
- must not be null.- Returns:
- new instance of
MongoJsonSchema
. - Since:
- 3.4
-
mergeWith
Create a newMongoJsonSchema
merging properties from the given sources.- Parameters:
sources
- must not be null.- Returns:
- new instance of
MongoJsonSchema
. - Since:
- 3.4
-
mergeWith
Create a newMongoJsonSchema
merging properties from the given sources.- Parameters:
sources
- must not be null.- Returns:
- new instance of
MongoJsonSchema
. - Since:
- 3.4
-
mergeWith
default MongoJsonSchema mergeWith(Collection<MongoJsonSchema> sources, MongoJsonSchema.ConflictResolutionFunction conflictResolutionFunction) Create a newMongoJsonSchema
merging properties from the given sources.- Parameters:
sources
- must not be null.- Returns:
- new instance of
MongoJsonSchema
. - Since:
- 3.4
-
builder
Obtain a newMongoJsonSchema.MongoJsonSchemaBuilder
to fluently define the schema.- Returns:
- new instance of
MongoJsonSchema.MongoJsonSchemaBuilder
.
-