public class DefaultMongoTypeMapper extends DefaultTypeMapper<org.bson.conversions.Bson> implements MongoTypeMapper
MongoTypeMapper allowing configuration of the key to lookup and store type
information in Document. The key defaults to DEFAULT_TYPE_KEY. Actual type-to-String
conversion and back is done in #getTypeString(TypeInformation) or #getTypeInformation(String)
respectively.| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultMongoTypeMapper.DocumentTypeAliasAccessor
TypeAliasAccessor to store aliases in a Document. |
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_TYPE_KEY |
| Constructor and Description |
|---|
DefaultMongoTypeMapper()
Create a new
MongoTypeMapper with fully-qualified type hints using _class. |
DefaultMongoTypeMapper(String typeKey)
Create a new
MongoTypeMapper with fully-qualified type hints using typeKey. |
DefaultMongoTypeMapper(String typeKey,
List<? extends TypeInformationMapper> mappers)
Create a new
MongoTypeMapper with fully-qualified type hints using typeKey. |
DefaultMongoTypeMapper(String typeKey,
MappingContext<? extends PersistentEntity<?,?>,?> mappingContext)
Create a new
MongoTypeMapper with fully-qualified type hints using typeKey. |
DefaultMongoTypeMapper(String typeKey,
MappingContext<? extends PersistentEntity<?,?>,?> mappingContext,
UnaryOperator<Class<?>> writeTarget)
Create a new
MongoTypeMapper with fully-qualified type hints using typeKey. |
| Modifier and Type | Method and Description |
|---|---|
protected TypeInformation<?> |
getFallbackTypeFor(org.bson.conversions.Bson source) |
Class<?> |
getWriteTargetTypeFor(Class<?> source)
Compute the target type for a given source considering
CustomConversions. |
boolean |
isTypeKey(String key)
Returns whether the given key is the type key.
|
void |
writeTypeRestrictions(org.bson.Document result,
Set<Class<?>> restrictedTypes)
Writes type restrictions to the given
Document. |
getAliasFor, readType, readType, writeType, writeTypeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitreadType, readType, writeType, writeTypepublic static final String DEFAULT_TYPE_KEY
public DefaultMongoTypeMapper()
MongoTypeMapper with fully-qualified type hints using _class.public DefaultMongoTypeMapper(@Nullable String typeKey)
MongoTypeMapper with fully-qualified type hints using typeKey.typeKey - name of the field to read and write type hints. Can be null to disable type hints.public DefaultMongoTypeMapper(@Nullable String typeKey, MappingContext<? extends PersistentEntity<?,?>,?> mappingContext)
MongoTypeMapper with fully-qualified type hints using typeKey.typeKey - name of the field to read and write type hints. Can be null to disable type hints.mappingContext - the mapping context.public DefaultMongoTypeMapper(@Nullable String typeKey, MappingContext<? extends PersistentEntity<?,?>,?> mappingContext, UnaryOperator<Class<?>> writeTarget)
MongoTypeMapper with fully-qualified type hints using typeKey. Uses
UnaryOperator to apply CustomConversions.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.MappingMongoConverter.getWriteTarget(Class)public DefaultMongoTypeMapper(@Nullable String typeKey, List<? extends TypeInformationMapper> mappers)
MongoTypeMapper with fully-qualified type hints using typeKey. Uses
TypeInformationMapper to map type hints.typeKey - name of the field to read and write type hints. Can be null to disable type hints.mappers - public boolean isTypeKey(String key)
MongoTypeMapperisTypeKey in interface MongoTypeMapperpublic void writeTypeRestrictions(org.bson.Document result,
@Nullable
Set<Class<?>> restrictedTypes)
MongoTypeMapperDocument. 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 given
restrictedTypes.writeTypeRestrictions in interface MongoTypeMapperresult - must not be nullrestrictedTypes - must not be nullpublic Class<?> getWriteTargetTypeFor(Class<?> source)
MongoTypeMapperCustomConversions.getWriteTargetTypeFor in interface MongoTypeMappersource - the source type.protected TypeInformation<?> getFallbackTypeFor(org.bson.conversions.Bson source)
getFallbackTypeFor in class DefaultTypeMapper<org.bson.conversions.Bson>Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.