org.springframework.data.mongodb.core.convert
Class ConfigurableTypeMapper
java.lang.Object
org.springframework.data.mongodb.core.convert.DefaultTypeMapper
org.springframework.data.mongodb.core.convert.ConfigurableTypeMapper
- All Implemented Interfaces:
- TypeMapper
public class ConfigurableTypeMapper
- extends DefaultTypeMapper
TypeMapper
allowing to configure a Map
containing Class
to String
mappings that will
be used to map the values found under the configured type key (see DefaultTypeMapper.setTypeKey(String)
. This
allows declarative type mapping in a Spring config file for example.
- Author:
- Oliver Gierke
Method Summary |
protected org.springframework.data.util.TypeInformation<?> |
getTypeInformation(String value)
Returns the TypeInformation that shall be used when the given String value is found as type hint. |
protected String |
getTypeString(org.springframework.data.util.TypeInformation<?> typeInformation)
Turn the given type information into the String representation that shall be stored inside the DBObject . |
void |
setHandleUnmappedClasses(boolean handleUnmappedClasses)
Configures whether to try to handle unmapped classes by simply writing the class' name or loading the class as
specified in the superclass. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConfigurableTypeMapper
public ConfigurableTypeMapper(Map<? extends Class<?>,String> sourceTypeMap)
- Creates a new
ConfigurableTypeMapper
for the given type map.
- Parameters:
sourceTypeMap
- must not be null.
setHandleUnmappedClasses
public void setHandleUnmappedClasses(boolean handleUnmappedClasses)
- Configures whether to try to handle unmapped classes by simply writing the class' name or loading the class as
specified in the superclass. Defaults to false.
- Parameters:
handleUnmappedClasses
- the handleUnmappedClasses to set
getTypeInformation
protected org.springframework.data.util.TypeInformation<?> getTypeInformation(String value)
- Description copied from class:
DefaultTypeMapper
- Returns the
TypeInformation
that shall be used when the given String
value is found as type hint.
The default implementation will simply interpret the given value as fully-qualified class name and try to load the
class. Will return null in case the given String
is empty. Will not be called in case no
String
was found for the configured type key at all.
- Overrides:
getTypeInformation
in class DefaultTypeMapper
- Parameters:
value
- the type to load, must not be null.
- Returns:
- the type to be used for the given
String
representation or null if nothing found or the
class cannot be loaded.
getTypeString
protected String getTypeString(org.springframework.data.util.TypeInformation<?> typeInformation)
- Description copied from class:
DefaultTypeMapper
- Turn the given type information into the String representation that shall be stored inside the
DBObject
. If
the returned String is null no type information will be stored. Default implementation simply returns
the fully-qualified class name.
- Overrides:
getTypeString
in class DefaultTypeMapper
- Parameters:
typeInformation
- must not be null.
- Returns:
- the String representation to be stored or null if no type information shall be stored.
Copyright © 2011. All Rights Reserved.