org.springframework.data.convert

## Class DefaultTypeMapper<S>

- java.lang.Object
- - org.springframework.data.convert.DefaultTypeMapper<S>

All Implemented Interfaces:
  TypeMapper<S>

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

Default implementation of `TypeMapper`.

Author:
  Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch

### Constructor Summary

Constructors
Constructor and Description
`DefaultTypeMapper(TypeAliasAccessor<S> accessor)` Creates a new `DefaultTypeMapper` using the given `TypeAliasAccessor`.
`DefaultTypeMapper(TypeAliasAccessor<S> accessor, List<? extends TypeInformationMapper> mappers)` Creates a new `DefaultTypeMapper` using the given `TypeAliasAccessor` and `TypeInformationMapper` s.
`DefaultTypeMapper(TypeAliasAccessor<S> accessor, MappingContext<? extends PersistentEntity<?,?>,?> mappingContext, List<? extends TypeInformationMapper> additionalMappers)` Creates a new `DefaultTypeMapper` using the given `TypeAliasAccessor`, `MappingContext` and additional `TypeInformationMapper`s.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected Alias` `getAliasFor(TypeInformation<?> info)` Returns the alias to be used for the given `TypeInformation`.
`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)

Creates a new `DefaultTypeMapper` using the given `TypeAliasAccessor`. It will use a `SimpleTypeInformationMapper` to calculate type aliases.

Parameters:
  `accessor` - must not be null.

#### DefaultTypeMapper

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

Creates a new `DefaultTypeMapper` using the given `TypeAliasAccessor` and `TypeInformationMapper` s.

Parameters:
  `accessor` - must not be null.
  `mappers` - must not be null.

#### DefaultTypeMapper

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

Creates a new `DefaultTypeMapper` using the given `TypeAliasAccessor`, `MappingContext` and additional `TypeInformationMapper`s. Will register a `MappingContextTypeInformationMapper` before the given additional mappers.

Parameters:
  `accessor` - must not be null.
  `mappingContext` -
  `additionalMappers` - must not be null.

### Method Detail

#### readType

    @Nullable
    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.
  `basicType` - must not be null.
Returns:

#### getFallbackTypeFor

    @Nullable
    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.

#### getAliasFor

    protected final Alias getAliasFor(TypeInformation<?> info)

Returns the alias to be used for the given `TypeInformation`.

Parameters:
  `info` - must not be null
Returns:
  the alias for the given `TypeInformation` or null of none was found or all mappers returned null.