public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware
MongoConverter that uses a MappingContext to do sophisticated mapping of domain objects to
Document.| Modifier and Type | Field and Description |
|---|---|
protected ApplicationContext |
applicationContext |
protected CodecRegistryProvider |
codecRegistryProvider |
protected org.springframework.data.mongodb.core.convert.DefaultDbRefProxyHandler |
dbRefProxyHandler |
protected DbRefResolver |
dbRefResolver |
protected QueryMapper |
idMapper |
protected static org.slf4j.Logger |
LOGGER |
protected String |
mapKeyDotReplacement |
protected MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
mappingContext |
protected MongoTypeMapper |
typeMapper |
conversions, conversionService, instantiators| Constructor and Description |
|---|
MappingMongoConverter(DbRefResolver dbRefResolver,
MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
|
MappingMongoConverter(MongoDbFactory mongoDbFactory,
MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
Deprecated.
use the constructor taking a
DbRefResolver instead. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCustomTypeKeyIfNecessary(TypeInformation<?> type,
Object value,
org.bson.conversions.Bson bson)
Adds custom type information to the given
Document if necessary. |
Object |
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 given
TypeInformation differs from the given object type. |
protected List<Object> |
createCollection(Collection<?> collection,
MongoPersistentProperty property)
Writes the given
Collection using the given MongoPersistentProperty information. |
protected com.mongodb.DBRef |
createDBRef(Object target,
MongoPersistentProperty property) |
protected org.bson.conversions.Bson |
createMap(Map<Object,Object> map,
MongoPersistentProperty property)
Writes the given
Map using the given MongoPersistentProperty information. |
MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
getMappingContext() |
MongoTypeMapper |
getTypeMapper()
Returns thw
TypeMapper being used to write type information into Documents created with that
converter. |
Object |
getValueInternal(MongoPersistentProperty prop,
org.bson.conversions.Bson bson,
SpELExpressionEvaluator evaluator,
org.springframework.data.mongodb.core.convert.ObjectPath path)
Resolves the value for the given
MongoPersistentProperty within the given Document using the given
SpELExpressionEvaluator and ObjectPath. |
Class<?> |
getWriteTarget(Class<?> source)
Get the conversion target type if defined or return the source.
|
List<Object> |
maybeConvertList(Iterable<?> source,
TypeInformation<?> typeInformation) |
protected String |
potentiallyEscapeMapKey(String source)
Potentially replaces dots in the given map key with the configured map key replacement if configured or aborts
conversion if none is configured.
|
protected String |
potentiallyUnescapeMapKey(String source)
Translates the map key replacements in the given key just read with a dot in case a map key replacement has been
configured.
|
<S> S |
read(Class<S> clazz,
org.bson.conversions.Bson bson) |
protected <S> S |
read(TypeInformation<S> type,
org.bson.conversions.Bson bson) |
protected Map<Object,Object> |
readMap(TypeInformation<?> type,
org.bson.conversions.Bson bson,
org.springframework.data.mongodb.core.convert.ObjectPath path)
|
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setCodecRegistryProvider(CodecRegistryProvider codecRegistryProvider)
Configure a
CodecRegistryProvider that provides native MongoDB codecs for
reading values. |
void |
setMapKeyDotReplacement(String mapKeyDotReplacement)
Configure the characters dots potentially contained in a
Map shall be replaced with. |
void |
setTypeMapper(MongoTypeMapper typeMapper)
Configures the
MongoTypeMapper to be used to add type information to Documents created by the
converter and how to lookup type information from Documents when reading them. |
com.mongodb.DBRef |
toDBRef(Object object,
MongoPersistentProperty referringProperty)
Creates a
DBRef to refer to the given object. |
MappingMongoConverter |
with(MongoDbFactory dbFactory)
|
void |
write(Object obj,
org.bson.conversions.Bson bson)
Root entry method into write conversion.
|
protected void |
writeInternal(Object obj,
org.bson.conversions.Bson bson,
MongoPersistentEntity<?> entity) |
protected void |
writeInternal(Object obj,
org.bson.conversions.Bson bson,
TypeInformation<?> typeHint)
Internal write conversion method which should be used for nested invocations.
|
protected org.bson.conversions.Bson |
writeMapInternal(Map<Object,Object> obj,
org.bson.conversions.Bson bson,
TypeInformation<?> propertyType)
|
protected void |
writePropertyInternal(Object obj,
org.springframework.data.mongodb.core.convert.DocumentAccessor accessor,
MongoPersistentProperty prop) |
afterPropertiesSet, getConversionService, setCustomConversions, setInstantiatorsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconvertId, mapValueToTargetTypeconvertToMongoTypeprotected static final org.slf4j.Logger LOGGER
protected final MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext
protected final QueryMapper idMapper
protected final DbRefResolver dbRefResolver
protected final org.springframework.data.mongodb.core.convert.DefaultDbRefProxyHandler dbRefProxyHandler
@Nullable protected ApplicationContext applicationContext
protected MongoTypeMapper typeMapper
@Nullable protected CodecRegistryProvider codecRegistryProvider
public MappingMongoConverter(DbRefResolver dbRefResolver, MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
dbRefResolver - must not be null.mappingContext - must not be null.@Deprecated public MappingMongoConverter(MongoDbFactory mongoDbFactory, MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
DbRefResolver instead.mongoDbFactory - must not be null.mappingContext - must not be null.public void setTypeMapper(@Nullable MongoTypeMapper typeMapper)
MongoTypeMapper to be used to add type information to Documents created by the
converter and how to lookup type information from Documents when reading them. Uses a
DefaultMongoTypeMapper by default. Setting this to null will reset the TypeMapper to the
default one.typeMapper - the typeMapper to set. Can be null.public MongoTypeMapper getTypeMapper()
MongoConverterTypeMapper being used to write type information into Documents created with that
converter.getTypeMapper in interface MongoConverterpublic void setMapKeyDotReplacement(@Nullable String mapKeyDotReplacement)
Map shall be replaced with. By default we don't do
any translation but rather reject a Map with keys containing dots causing the conversion for the entire
object to fail. If further customization of the translation is needed, have a look at
potentiallyEscapeMapKey(String) as well as potentiallyUnescapeMapKey(String).mapKeyDotReplacement - the mapKeyDotReplacement to set. Can be null.public void setCodecRegistryProvider(@Nullable CodecRegistryProvider codecRegistryProvider)
CodecRegistryProvider that provides native MongoDB codecs for
reading values.codecRegistryProvider - can be null.public MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> getMappingContext()
getMappingContext in interface EntityConverter<MongoPersistentEntity<?>,MongoPersistentProperty,Object,org.bson.conversions.Bson>public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext in interface ApplicationContextAwareBeansExceptionpublic <S> S read(Class<S> clazz, org.bson.conversions.Bson bson)
read in interface EntityReader<Object,org.bson.conversions.Bson>protected <S> S read(TypeInformation<S> type, org.bson.conversions.Bson bson)
public com.mongodb.DBRef toDBRef(Object object, @Nullable MongoPersistentProperty referringProperty)
MongoWriterDBRef to refer to the given object.toDBRef in interface MongoWriter<Object>object - the object to create a DBRef 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
the DBRef object to create. Can be null.public void write(Object obj, org.bson.conversions.Bson bson)
Document. Shouldn't be called for
nested conversions.write in interface EntityWriter<Object,org.bson.conversions.Bson>org.springframework.data.mongodb.core.convert.MongoWriter#write(java.lang.Object, com.mongodb.Document)protected void writeInternal(@Nullable Object obj, org.bson.conversions.Bson bson, @Nullable TypeInformation<?> typeHint)
obj - bson - typeHint - protected void writeInternal(@Nullable Object obj, org.bson.conversions.Bson bson, @Nullable MongoPersistentEntity<?> entity)
protected void writePropertyInternal(@Nullable Object obj, org.springframework.data.mongodb.core.convert.DocumentAccessor accessor, MongoPersistentProperty prop)
protected List<Object> createCollection(Collection<?> collection, MongoPersistentProperty property)
Collection using the given MongoPersistentProperty information.collection - must not be null.property - must not be null.protected org.bson.conversions.Bson createMap(Map<Object,Object> map, MongoPersistentProperty property)
Map using the given MongoPersistentProperty information.map - must not null.property - must not be null.protected org.bson.conversions.Bson writeMapInternal(Map<Object,Object> obj, org.bson.conversions.Bson bson, TypeInformation<?> propertyType)
obj - must not be null.bson - must not be null.propertyType - must not be null.protected String potentiallyEscapeMapKey(String source)
source - setMapKeyDotReplacement(String)protected String potentiallyUnescapeMapKey(String source)
source - protected void addCustomTypeKeyIfNecessary(@Nullable TypeInformation<?> type, Object value, org.bson.conversions.Bson bson)
Document if necessary. That is if the value is not the same as
the one given. This is usually the case if you store a subtype of the actual declared type of the property.type - value - must not be null.bson - must not be null.protected com.mongodb.DBRef createDBRef(Object target, MongoPersistentProperty property)
public Object getValueInternal(MongoPersistentProperty prop, org.bson.conversions.Bson bson, SpELExpressionEvaluator evaluator, org.springframework.data.mongodb.core.convert.ObjectPath path)
MongoPersistentProperty within the given Document using the given
SpELExpressionEvaluator and ObjectPath.protected Map<Object,Object> readMap(TypeInformation<?> type, org.bson.conversions.Bson bson, org.springframework.data.mongodb.core.convert.ObjectPath path)
type - the Map TypeInformation to be used to unmarshall this Document.bson - must not be nullpath - must not be null@Nullable public Object convertToMongoType(@Nullable Object obj, TypeInformation<?> typeInformation)
MongoWriterTypeInformation differs from the given object type.convertToMongoType in interface MongoWriter<Object>obj - can be null.typeInformation - can be null.public List<Object> maybeConvertList(Iterable<?> source, TypeInformation<?> typeInformation)
public Class<?> getWriteTarget(Class<?> source)
source - must not be null.public MappingMongoConverter with(MongoDbFactory dbFactory)
MappingMongoConverter. Never null.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.