Class DefaultMongoTypeMapper
java.lang.Object
org.springframework.data.convert.DefaultTypeMapper<org.bson.conversions.Bson>
org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,TypeMapper<org.bson.conversions.Bson>
,MongoTypeMapper
public class DefaultMongoTypeMapper
extends DefaultTypeMapper<org.bson.conversions.Bson>
implements MongoTypeMapper
Default implementation of
MongoTypeMapper
allowing configuration of the key to lookup and store type
information in Document
. The key defaults to DEFAULT_TYPE_KEY
.- Author:
- Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
TypeAliasAccessor
to store aliases in aDocument
. -
Field Summary
-
Constructor Summary
ConstructorDescriptionCreate a newMongoTypeMapper
with fully-qualified type hints using_class
.DefaultMongoTypeMapper
(String typeKey) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
.DefaultMongoTypeMapper
(String typeKey, List<? extends TypeInformationMapper> mappers) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
.DefaultMongoTypeMapper
(String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
.DefaultMongoTypeMapper
(String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, UnaryOperator<Class<?>> writeTarget) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
. -
Method Summary
Modifier and TypeMethodDescriptionprotected TypeInformation<?>
getFallbackTypeFor
(org.bson.conversions.Bson source) Class<?>
getWriteTargetTypeFor
(Class<?> source) Compute the target type for a given source consideringCustomConversions
.boolean
Returns whether the given key is the type key.void
writeTypeRestrictions
(org.bson.Document result, Set<Class<?>> restrictedTypes) Writes type restrictions to the givenDocument
.Methods inherited from class org.springframework.data.convert.DefaultTypeMapper
getAliasFor, readType, readType, setBeanClassLoader, writeType, writeType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.convert.TypeMapper
readType, readType, writeType, writeType
-
Field Details
-
DEFAULT_TYPE_KEY
- See Also:
-
-
Constructor Details
-
DefaultMongoTypeMapper
public DefaultMongoTypeMapper()Create a newMongoTypeMapper
with fully-qualified type hints using_class
. -
DefaultMongoTypeMapper
Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
.- Parameters:
typeKey
- name of the field to read and write type hints. Can be null to disable type hints.
-
DefaultMongoTypeMapper
public DefaultMongoTypeMapper(@Nullable String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
.- Parameters:
typeKey
- name of the field to read and write type hints. Can be null to disable type hints.mappingContext
- the mapping context.
-
DefaultMongoTypeMapper
public DefaultMongoTypeMapper(@Nullable String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, UnaryOperator<Class<?>> writeTarget) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
. UsesUnaryOperator
to applyCustomConversions
.- Parameters:
typeKey
- name of the field to read and write type hints. Can be null to disable type hints.mappingContext
- the mapping context to look up types using type hints.- See Also:
-
DefaultMongoTypeMapper
public DefaultMongoTypeMapper(@Nullable String typeKey, List<? extends TypeInformationMapper> mappers) Create a newMongoTypeMapper
with fully-qualified type hints usingtypeKey
. UsesTypeInformationMapper
to map type hints.- Parameters:
typeKey
- name of the field to read and write type hints. Can be null to disable type hints.mappers
- must not be null.
-
-
Method Details
-
isTypeKey
Description copied from interface:MongoTypeMapper
Returns whether the given key is the type key.- Specified by:
isTypeKey
in interfaceMongoTypeMapper
- Returns:
-
writeTypeRestrictions
public void writeTypeRestrictions(org.bson.Document result, @Nullable Set<Class<?>> restrictedTypes) Description copied from interface:MongoTypeMapper
Writes type restrictions to the givenDocument
. This usually results in an$in
-clause to be generated that restricts the type-key (e.g._class
) to be in the set of type aliases for the givenrestrictedTypes
.- Specified by:
writeTypeRestrictions
in interfaceMongoTypeMapper
- Parameters:
result
- must not be nullrestrictedTypes
- must not be null
-
getWriteTargetTypeFor
Description copied from interface:MongoTypeMapper
Compute the target type for a given source consideringCustomConversions
.- Specified by:
getWriteTargetTypeFor
in interfaceMongoTypeMapper
- Parameters:
source
- the source type.- Returns:
- never null.
-
getFallbackTypeFor
- Overrides:
getFallbackTypeFor
in classDefaultTypeMapper<org.bson.conversions.Bson>
-