Interface MongoWriter<T>
- Type Parameters:
T
- the type of the object to convert to a Document
- All Superinterfaces:
EntityWriter<T,
org.bson.conversions.Bson>
- All Known Subinterfaces:
MongoConverter
- All Known Implementing Classes:
AbstractMongoConverter
,MappingMongoConverter
A MongoWriter is responsible for converting an object of type T to the native MongoDB representation Document.
- Author:
- Mark Pollack, Thomas Risberg, Oliver Gierke, Christoph Strobl
-
Method Summary
Modifier and TypeMethodDescriptiondefault Object
convertToMongoType
(Object obj) Converts the given object into one Mongo will be able to store natively.default Object
convertToMongoType
(Object obj, MongoPersistentEntity<?> entity) convertToMongoType
(Object obj, TypeInformation<?> typeInformation) Converts the given object into one Mongo will be able to store natively but retains the type information in case the givenTypeInformation
differs from the given object type.com.mongodb.DBRef
toDBRef
(Object object, MongoPersistentProperty referringProperty) Creates aDBRef
to refer to the given object.default DocumentPointer<?>
toDocumentPointer
(Object source, MongoPersistentProperty referringProperty) Creates a theDocumentPointer
representing the link to another entity.Methods inherited from interface org.springframework.data.convert.EntityWriter
write
-
Method Details
-
convertToMongoType
Converts the given object into one Mongo will be able to store natively. If the given object can already be stored as is, no conversion will happen.- Parameters:
obj
- can be null.- Returns:
-
convertToMongoType
@Nullable Object convertToMongoType(@Nullable Object obj, @Nullable TypeInformation<?> typeInformation) Converts the given object into one Mongo will be able to store natively but retains the type information in case the givenTypeInformation
differs from the given object type.- Parameters:
obj
- can be null.typeInformation
- can be null.- Returns:
-
convertToMongoType
-
toDBRef
Creates aDBRef
to refer to the given object.- Parameters:
object
- the object to create aDBRef
to link to. The object's type has to carry an id attribute.referringProperty
- the client-side property referring to the object which might carry additional metadata for theDBRef
object to create. Can be null.- Returns:
- will never be null.
-
toDocumentPointer
default DocumentPointer<?> toDocumentPointer(Object source, @Nullable MongoPersistentProperty referringProperty) Creates a theDocumentPointer
representing the link to another entity.- Parameters:
source
- the object to create a document link to.referringProperty
- the client-side property referring to the object which might carry additional metadata for theDBRef
object to create. Can be null.- Returns:
- will never be null.
- Since:
- 3.3
-