|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.data.document.mongodb.convert.SimpleMongoConverter
public class SimpleMongoConverter
Basic MongoConverter
implementation to convert between domain classes and DBObject
s.
Field Summary | |
---|---|
private GenericConversionService |
conversionService
|
private static Log |
LOG
|
private static java.util.List<java.lang.Class<?>> |
MONGO_TYPES
|
private static java.util.Set<java.lang.String> |
SIMPLE_TYPES
|
Constructor Summary | |
---|---|
SimpleMongoConverter()
Creates a SimpleMongoConverter . |
Method Summary | ||
---|---|---|
void |
afterPropertiesSet()
|
|
ObjectId |
convertObjectId(java.lang.Object id)
Returns the ObjectId instance for the given id. |
|
|
convertObjectId(ObjectId id,
java.lang.Class<T> targetType)
Converts the given ObjectId to the given target type. |
|
protected java.util.Map<java.lang.String,java.lang.Object> |
createMap()
Create a Map instance. |
|
protected MongoBeanWrapper |
createWrapper(java.lang.Object target,
boolean fieldAccess)
Callback to allow customizing creation of a MongoBeanWrapper . |
|
private java.lang.Class<?> |
getCustomTargetType(java.lang.Object obj)
Returns whether the ConversionService has a custom Converter registered that can convert the given
object into one of the types supported by MongoDB. |
|
java.util.List<java.lang.Class<?>> |
getGenericParameters(java.lang.reflect.Type genericParameterType)
|
|
private void |
initializeConverters()
Initializes additional converters that handle ObjectId conversion. |
|
protected static boolean |
isSimpleType(java.lang.Class<?> propertyType)
|
|
|
read(java.lang.Class<S> clazz,
DBObject source)
Ready from the native MongoDB DBObject representation to an instance of the class T. |
|
private java.util.Collection<java.lang.Object> |
readCollection(MongoPropertyDescriptors.MongoPropertyDescriptor descriptor,
java.util.Collection<?> values)
Reads the given collection values (that are DBObject s potentially) into a Collection of domain
objects. |
|
private java.lang.Object |
readCompoundValue(MongoPropertyDescriptors.MongoPropertyDescriptor pd,
DBObject dbo)
Reads a compound value from the given DBObject for the given property. |
|
protected java.util.Map<?,?> |
readMap(MongoPropertyDescriptors.MongoPropertyDescriptor pd,
DBObject dbo,
java.lang.Class<?> targetType)
Reads every key/value pair from the DBObject into a Map instance. |
|
void |
setConverters(java.util.Set<?> converters)
Add custom Converter or ConverterFactory instances to be used that will take presidence over
using object traversal to convert and object to/from DBObject |
|
void |
write(java.lang.Object obj,
DBObject dbo)
Write the given object of type T to the native MongoDB object representation DBObject. |
|
protected void |
writeArray(DBObject dbo,
java.lang.String keyToUse,
java.lang.Object[] array)
Writes the given array to the given DBObject . |
|
private void |
writeCompoundValue(DBObject dbo,
java.lang.String keyToUse,
java.lang.Object value)
Writes the given CompoundComparator value to the given DBObject . |
|
protected void |
writeMap(DBObject dbo,
java.lang.String mapKey,
java.util.Map<java.lang.String,java.lang.Object> map)
Writes the given Map to the given DBObject . |
|
private void |
writeValue(DBObject dbo,
java.lang.String keyToUse,
java.lang.Object value)
Writes the given value to the given DBObject . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Log LOG
private static final java.util.List<java.lang.Class<?>> MONGO_TYPES
private static final java.util.Set<java.lang.String> SIMPLE_TYPES
private final GenericConversionService conversionService
Constructor Detail |
---|
public SimpleMongoConverter()
SimpleMongoConverter
.
Method Detail |
---|
private void initializeConverters()
ObjectId
conversion. Will register converters for supported
id types if none are registered for those conversion already. GenericConversionService
is configured.
public void setConverters(java.util.Set<?> converters)
Converter
or ConverterFactory
instances to be used that will take presidence over
using object traversal to convert and object to/from DBObject
converters
- public void write(java.lang.Object obj, DBObject dbo)
MongoWriter
write
in interface MongoWriter<java.lang.Object>
obj
- The object to convert to a DBObjectdbo
- The DBObject to use for writing.private void writeValue(DBObject dbo, java.lang.String keyToUse, java.lang.Object value)
DBObject
. Will skip null values.
dbo
- keyToUse
- value
- private void writeCompoundValue(DBObject dbo, java.lang.String keyToUse, java.lang.Object value)
CompoundComparator
value to the given DBObject
.
dbo
- keyToUse
- value
- private java.lang.Class<?> getCustomTargetType(java.lang.Object obj)
ConversionService
has a custom Converter
registered that can convert the given
object into one of the types supported by MongoDB.
obj
-
protected void writeMap(DBObject dbo, java.lang.String mapKey, java.util.Map<java.lang.String,java.lang.Object> map)
Map
to the given DBObject
.
dbo
- mapKey
- map
- protected void writeArray(DBObject dbo, java.lang.String keyToUse, java.lang.Object[] array)
DBObject
.
dbo
- keyToUse
- array
- public <S> S read(java.lang.Class<S> clazz, DBObject source)
MongoReader
DBObject
into it. So in case there's no real valid data inside
DBObject
for the given type, just return an empty instance of the given type.
read
in interface MongoReader<java.lang.Object>
clazz
- the type of the return valuesource
- theDBObject
private java.util.Collection<java.lang.Object> readCollection(MongoPropertyDescriptors.MongoPropertyDescriptor descriptor, java.util.Collection<?> values)
DBObject
s potentially) into a Collection
of domain
objects.
descriptor
- values
-
private java.lang.Object readCompoundValue(MongoPropertyDescriptors.MongoPropertyDescriptor pd, DBObject dbo)
DBObject
for the given property.
pd
- dbo
-
protected java.util.Map<java.lang.String,java.lang.Object> createMap()
Map
instance. Will return a HashMap
by default. Subclasses might want to override this
method to use a custom Map
implementation.
protected java.util.Map<?,?> readMap(MongoPropertyDescriptors.MongoPropertyDescriptor pd, DBObject dbo, java.lang.Class<?> targetType)
DBObject
into a Map
instance.
pd
- dbo
- targetType
-
protected static boolean isSimpleType(java.lang.Class<?> propertyType)
protected MongoBeanWrapper createWrapper(java.lang.Object target, boolean fieldAccess)
MongoBeanWrapper
.
target
- the target object to wrapfieldAccess
- whether to use field access or property access
public java.util.List<java.lang.Class<?>> getGenericParameters(java.lang.reflect.Type genericParameterType)
public <T> T convertObjectId(ObjectId id, java.lang.Class<T> targetType)
MongoConverter
ObjectId
to the given target type.
convertObjectId
in interface MongoConverter
T
- the actual type to createid
- the source ObjectId
targetType
- the target type to convert the ObjectId
to
public ObjectId convertObjectId(java.lang.Object id)
MongoConverter
ObjectId
instance for the given id.
convertObjectId
in interface MongoConverter
public void afterPropertiesSet()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |