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
Nested ClassesModifier and TypeClassDescriptionstatic final classTypeAliasAccessorto store aliases in aDocument. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newMongoTypeMapperwith fully-qualified type hints using_class.DefaultMongoTypeMapper(String typeKey) Create a newMongoTypeMapperwith fully-qualified type hints usingtypeKey.DefaultMongoTypeMapper(String typeKey, List<? extends TypeInformationMapper> mappers) Create a newMongoTypeMapperwith fully-qualified type hints usingtypeKey.DefaultMongoTypeMapper(String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext) Create a newMongoTypeMapperwith fully-qualified type hints usingtypeKey.DefaultMongoTypeMapper(String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, UnaryOperator<Class<?>> writeTarget) Create a newMongoTypeMapperwith 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.booleanReturns whether the given key is the type key.voidwriteTypeRestrictions(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, writeTypeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 newMongoTypeMapperwith fully-qualified type hints using_class. -
DefaultMongoTypeMapper
Create a newMongoTypeMapperwith 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 newMongoTypeMapperwith 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 newMongoTypeMapperwith fully-qualified type hints usingtypeKey. UsesUnaryOperatorto 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 newMongoTypeMapperwith fully-qualified type hints usingtypeKey. UsesTypeInformationMapperto 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:MongoTypeMapperReturns whether the given key is the type key.- Specified by:
isTypeKeyin interfaceMongoTypeMapper- Returns:
-
writeTypeRestrictions
public void writeTypeRestrictions(org.bson.Document result, @Nullable Set<Class<?>> restrictedTypes) Description copied from interface:MongoTypeMapperWrites 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:
writeTypeRestrictionsin interfaceMongoTypeMapper- Parameters:
result- must not be nullrestrictedTypes- must not be null
-
getWriteTargetTypeFor
Description copied from interface:MongoTypeMapperCompute the target type for a given source consideringCustomConversions.- Specified by:
getWriteTargetTypeForin interfaceMongoTypeMapper- Parameters:
source- the source type.- Returns:
- never null.
-
getFallbackTypeFor
- Overrides:
getFallbackTypeForin classDefaultTypeMapper<org.bson.conversions.Bson>
-