Spring Data Commons

org.springframework.data.convert
Class DefaultTypeMapper<S>

java.lang.Object
  extended by org.springframework.data.convert.DefaultTypeMapper<S>
All Implemented Interfaces:
TypeMapper<S>

public class DefaultTypeMapper<S>
extends Object
implements TypeMapper<S>

Default implementation of MongoTypeMapper allowing configuration of the key to lookup and store type information in DBObject. The key defaults to #DEFAULT_TYPE_KEY. Actual type-to-String conversion and back is done in #getTypeString(TypeInformation) or #getTypeInformation(String) respectively.

Author:
Oliver Gierke

Constructor Summary
DefaultTypeMapper(TypeAliasAccessor<S> accessor)
           
DefaultTypeMapper(TypeAliasAccessor<S> accessor, List<? extends TypeInformationMapper> mappers)
           
DefaultTypeMapper(TypeAliasAccessor<S> accessor, MappingContext<? extends PersistentEntity<?,?>,?> mappingContext, List<? extends TypeInformationMapper> additionalMappers)
           
 
Method Summary
protected  TypeInformation<?> getFallbackTypeFor(S source)
          Returns the type fallback TypeInformation in case none could be extracted from the given source.
 TypeInformation<?> readType(S source)
          Reads the TypeInformation from the given source.
<T> TypeInformation<? extends T>
readType(S source, TypeInformation<T> basicType)
          Returns the TypeInformation from the given source if it is a more concrete type than the given default one.
 void writeType(Class<?> type, S dbObject)
          Writes type information for the given type into the given sink.
 void writeType(TypeInformation<?> info, S sink)
          Writes type information for the given TypeInformation into the given sink.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTypeMapper

public DefaultTypeMapper(TypeAliasAccessor<S> accessor)

DefaultTypeMapper

public DefaultTypeMapper(TypeAliasAccessor<S> accessor,
                         List<? extends TypeInformationMapper> mappers)

DefaultTypeMapper

public DefaultTypeMapper(TypeAliasAccessor<S> accessor,
                         MappingContext<? extends PersistentEntity<?,?>,?> mappingContext,
                         List<? extends TypeInformationMapper> additionalMappers)
Method Detail

readType

public TypeInformation<?> readType(S source)
Description copied from interface: TypeMapper
Reads the TypeInformation from the given source.

Specified by:
readType in interface TypeMapper<S>
Parameters:
source - must not be null.
Returns:

readType

public <T> TypeInformation<? extends T> readType(S source,
                                                 TypeInformation<T> basicType)
Description copied from interface: TypeMapper
Returns the TypeInformation from the given source if it is a more concrete type than the given default one.

Specified by:
readType in interface TypeMapper<S>
Parameters:
source - must not be null.
Returns:

getFallbackTypeFor

protected TypeInformation<?> getFallbackTypeFor(S source)
Returns the type fallback TypeInformation in case none could be extracted from the given source.

Parameters:
source - will never be null.
Returns:

writeType

public void writeType(Class<?> type,
                      S dbObject)
Description copied from interface: TypeMapper
Writes type information for the given type into the given sink.

Specified by:
writeType in interface TypeMapper<S>
Parameters:
type - must not be null.
dbObject - must not be null.

writeType

public void writeType(TypeInformation<?> info,
                      S sink)
Description copied from interface: TypeMapper
Writes type information for the given TypeInformation into the given sink.

Specified by:
writeType in interface TypeMapper<S>
Parameters:
info - must not be null.
sink - must not be null.

Spring Data Commons

Copyright © 2012. All Rights Reserved.