|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.modelmapper.ModelMapper
public class ModelMapper
ModelMapper framework entry point. Performs object mapping and contains mapping related configuration.
map
.createTypeMap
.addMappings
supplying a PropertyMap
.
Constructor Summary | |
---|---|
ModelMapper()
Creates a new ModelMapper. |
Method Summary | ||
---|---|---|
|
addConverter(Converter<S,D> converter)
Registers the converter to use when mapping instances of types S to D . |
|
|
addMappings(PropertyMap<S,D> propertyMap)
Adds mappings from the propertyMap into the TypeMap corresponding to source type
S and destination type D . |
|
|
createTypeMap(Class<S> sourceType,
Class<D> destinationType)
Creates a TypeMap for the sourceType and destinationType using the
ModelMapper's configuration. |
|
|
createTypeMap(Class<S> sourceType,
Class<D> destinationType,
Configuration configuration)
Creates a TypeMap for the sourceType and destinationType using the given
configuration . |
|
Configuration |
getConfiguration()
Returns the ModelMapper's configuration. |
|
|
getTypeMap(Class<S> sourceType,
Class<D> destinationType)
Returns the TypeMap for the sourceType and destinationType , else returns
null if none exists. |
|
Collection<TypeMap<?,?>> |
getTypeMaps()
Returns all TypeMaps for the ModelMapper. |
|
|
map(Object source,
Class<D> destinationType)
Maps source to an instance of destinationType . |
|
void |
map(Object source,
Object destination)
Maps source to destination . |
|
void |
validate()
Validates that every top level destination property for each configured TypeMap is mapped to one and only one source property, or that a Converter was
set for the TypeMap. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ModelMapper()
Method Detail |
---|
public <S,D> void addConverter(Converter<S,D> converter)
converter
to use when mapping instances of types S
to D
.
The converter
will be set against TypeMap corresponding to the converter
's type
arguments S
and D
.
S
- source typeD
- destination typeconverter
- to register
IllegalArgumentException
- if converter
is null or if type arguments S
and D
are not declared for the converter
TypeMap.setConverter(Converter)
public <S,D> TypeMap<S,D> addMappings(PropertyMap<S,D> propertyMap)
propertyMap
into the TypeMap corresponding to source type
S
and destination type D
. Explicit mappings defined in the propertyMap
will override any implicit mappings for the same properties.
S
- source typeD
- destination typepropertyMap
- from which mappings should be loaded
propertyMap
ConfigurationException
- if an error occurred while reading mappings from the
propertyMap
IllegalArgumentException
- if propertyMap
is null
ConfigurationException
- if a configuration error occurs while adding mappings for the
propertyMap
public <S,D> TypeMap<S,D> createTypeMap(Class<S> sourceType, Class<D> destinationType)
sourceType
and destinationType
using the
ModelMapper's configuration.
S
- source typeD
- destination typesourceType
- destinationType
-
IllegalStateException
- if a TypeMap already exists for sourceType
and
destinationType
ConfigurationException
- if the ModelMapper cannot create the TypeMapgetTypeMap(Class, Class)
public <S,D> TypeMap<S,D> createTypeMap(Class<S> sourceType, Class<D> destinationType, Configuration configuration)
sourceType
and destinationType
using the given
configuration
.
S
- source typeD
- destination typesourceType
- destinationType
- configuration
-
IllegalStateException
- if a TypeMap already exists for sourceType
and
destinationType
ConfigurationException
- if the ModelMapper cannot create the TypeMapgetTypeMap(Class, Class)
public Configuration getConfiguration()
public <S,D> TypeMap<S,D> getTypeMap(Class<S> sourceType, Class<D> destinationType)
sourceType
and destinationType
, else returns
null
if none exists.
S
- source typeD
- destination type
IllegalArgumentException
- is sourceType
or destinationType
are nullcreateTypeMap(Class, Class)
public Collection<TypeMap<?,?>> getTypeMaps()
public <D> D map(Object source, Class<D> destinationType)
source
to an instance of destinationType
. Mapping is performed according
to the corresponding TypeMap. If no TypeMap exists for source.getClass()
and
destinationType
then one is created.
D
- destination typesource
- object to map fromdestinationType
- type to map to
destinationType
IllegalArgumentException
- if source
or destinationType
are null
ConfigurationException
- if the ModelMapper cannot find or create the TypeMap
MappingException
- if a runtime error occurs while mappingpublic void map(Object source, Object destination)
source
to destination
. Mapping is performed according to the corresponding
TypeMap. If no TypeMap exists for source.getClass()
and destination.getClass()
then one is created.
source
- object to map fromdestination
- object to map to
IllegalArgumentException
- if source
or destination
are null
ConfigurationException
- if the ModelMapper cannot find or create the TypeMap
MappingException
- if an error occurs while mappingpublic void validate()
Converter
was
set
for the TypeMap. If not, a ConfigurationException
is thrown detailing any missing mappings.
ValidationException
- if any TypeMaps contain unmapped properties
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |