Module spring.data.mongodb
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 interfaceA resolution function that is called on conflicting paths when trying to merge properties with different values into a single value.static classMongoJsonSchema.MongoJsonSchemaBuilderprovides a fluent API for defining aMongoJsonSchema. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Obtain a newMongoJsonSchema.MongoJsonSchemaBuilderto fluently define the schema.static MongoJsonSchemamerge(MongoJsonSchema... sources) Create a newMongoJsonSchemamerging properties from the given sources.static MongoJsonSchemamerge(MongoJsonSchema.ConflictResolutionFunction mergeFunction, MongoJsonSchema... sources) Create a newMongoJsonSchemamerging properties from the given sources.default MongoJsonSchemamergeWith(Collection<MongoJsonSchema> sources) Create a newMongoJsonSchemamerging properties from the given sources.default MongoJsonSchemamergeWith(Collection<MongoJsonSchema> sources, MongoJsonSchema.ConflictResolutionFunction conflictResolutionFunction) Create a newMongoJsonSchemamerging properties from the given sources.default MongoJsonSchemamergeWith(MongoJsonSchema... sources) Create a newMongoJsonSchemamerging properties from the given sources.static MongoJsonSchemaof(org.bson.Document document) Create a newMongoJsonSchemafor a given rootDocumentcontaining the schema definition.static MongoJsonSchemaof(JsonSchemaObject root) Create a newMongoJsonSchemafor a given root object.org.bson.DocumentCreate theDocumentdefining the schema.default org.bson.Document
-
Method Details
-
toDocument
default org.bson.Document toDocument()Create the$jsonSchemaDocumentcontaining the specifiedschemaDocument().
Property and field names need to be mapped to the domain type ones by running theDocumentthrough aJsonSchemaMapperto apply field name customization.- Returns:
- never null.
-
schemaDocument
org.bson.Document schemaDocument()Create theDocumentdefining the schema.
Property and field names need to be mapped to the domain type property by running theDocumentthrough aJsonSchemaMapperto apply field name customization.- Returns:
- never null.
- Since:
- 3.3
-
of
Create a newMongoJsonSchemafor a given root object.- Parameters:
root- must not be null.- Returns:
- new instance of
MongoJsonSchema.
-
of
Create a newMongoJsonSchemafor a given rootDocumentcontaining the schema definition.- Parameters:
document- must not be null.- Returns:
- new instance of
MongoJsonSchema.
-
merge
Create a newMongoJsonSchemamerging 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 newMongoJsonSchemamerging properties from the given sources.- Parameters:
sources- must not be null.- Returns:
- new instance of
MongoJsonSchema. - Since:
- 3.4
-
mergeWith
Create a newMongoJsonSchemamerging properties from the given sources.- Parameters:
sources- must not be null.- Returns:
- new instance of
MongoJsonSchema. - Since:
- 3.4
-
mergeWith
Create a newMongoJsonSchemamerging 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 newMongoJsonSchemamerging properties from the given sources.- Parameters:
sources- must not be null.- Returns:
- new instance of
MongoJsonSchema. - Since:
- 3.4
-
builder
Obtain a newMongoJsonSchema.MongoJsonSchemaBuilderto fluently define the schema.- Returns:
- new instance of
MongoJsonSchema.MongoJsonSchemaBuilder.
-