Interface MongoConverter
- All Superinterfaces:
CodecRegistryProvider
,EntityConverter<MongoPersistentEntity<?>,
,MongoPersistentProperty, Object, org.bson.conversions.Bson> EntityReader<Object,
,org.bson.conversions.Bson> EntityWriter<Object,
,org.bson.conversions.Bson> MongoWriter<Object>
- All Known Implementing Classes:
AbstractMongoConverter
,MappingMongoConverter
public interface MongoConverter
extends EntityConverter<MongoPersistentEntity<?>,MongoPersistentProperty,Object,org.bson.conversions.Bson>, MongoWriter<Object>, EntityReader<Object,org.bson.conversions.Bson>, CodecRegistryProvider
Central Mongo specific converter interface which combines
MongoWriter
and EntityReader
.- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch, Ryan Gibb
-
Method Summary
Modifier and TypeMethodDescriptiondefault Object
Converts the given raw id value into eitherObjectId
orString
.default org.bson.codecs.configuration.CodecRegistry
Get the underlyingCodecRegistry
used by the MongoDB Java driver.Returns theCustomConversions
for this converter.Returns theProjectionFactory
for this converter.Returns theTypeMapper
being used to write type information intoDocument
s created with that converter.default <S,
T> T mapValueToTargetType
(S source, Class<T> targetType, DbRefResolver dbRefResolver) Mapping function capable of converting values into a desired target type by eg. extracting the actual java type from a givenBsonValue
.<R> R
project
(EntityProjection<R, ?> descriptor, org.bson.conversions.Bson bson) Apply a projection toBson
and return the projection return typeR
.Methods inherited from interface org.springframework.data.mongodb.CodecRegistryProvider
getCodecFor, hasCodecFor
Methods inherited from interface org.springframework.data.convert.EntityConverter
getConversionService, getMappingContext
Methods inherited from interface org.springframework.data.convert.EntityReader
read
Methods inherited from interface org.springframework.data.convert.EntityWriter
write
Methods inherited from interface org.springframework.data.mongodb.core.convert.MongoWriter
convertToMongoType, convertToMongoType, convertToMongoType, toDBRef, toDocumentPointer
-
Method Details
-
getTypeMapper
MongoTypeMapper getTypeMapper()Returns theTypeMapper
being used to write type information intoDocument
s created with that converter.- Returns:
- will never be null.
-
getProjectionFactory
ProjectionFactory getProjectionFactory()Returns theProjectionFactory
for this converter.- Returns:
- will never be null.
- Since:
- 3.4
-
getCustomConversions
CustomConversions getCustomConversions()Returns theCustomConversions
for this converter.- Returns:
- will never be null.
- Since:
- 3.4
-
project
Apply a projection toBson
and return the projection return typeR
.Non-projecting
descriptors fall back toregular object materialization
.- Type Parameters:
R
-- Parameters:
descriptor
- the projection descriptor, must not be null.bson
- must not be null.- Returns:
- a new instance of the projection return type
R
. - Since:
- 3.4
-
mapValueToTargetType
@Nullable default <S,T> T mapValueToTargetType(S source, Class<T> targetType, DbRefResolver dbRefResolver) Mapping function capable of converting values into a desired target type by eg. extracting the actual java type from a givenBsonValue
.- Type Parameters:
S
-T
-- Parameters:
targetType
- must not be null.dbRefResolver
- must not be null.- Returns:
- new typed
Function
. - Throws:
IllegalArgumentException
- if targetType is null.- Since:
- 2.1
-
convertId
Converts the given raw id value into eitherObjectId
orString
.- Parameters:
id
- can be null.targetType
- must not be null.- Returns:
- null if source id is already null.
- Since:
- 2.2
-
getCodecRegistry
default org.bson.codecs.configuration.CodecRegistry getCodecRegistry()Description copied from interface:CodecRegistryProvider
Get the underlyingCodecRegistry
used by the MongoDB Java driver.- Specified by:
getCodecRegistry
in interfaceCodecRegistryProvider
- Returns:
- never null.
-