S
- source typeD
- destination typepublic interface TypeMap<S,D>
Modifier and Type | Method and Description |
---|---|
<V> TypeMap<S,D> |
addMapping(SourceGetter<S> sourceGetter,
DestinationSetter<D,V> destinationSetter)
Adds a mapping into
TypeMap by defining sourceGetter -> destinationSetter |
TypeMap<S,D> |
addMappings(ExpressionMap<S,D> mapper)
Add a mapping into
TypeMap by defining a mapper action
You can chain addMappings contains only one property mapping like |
TypeMap<S,D> |
addMappings(PropertyMap<S,D> propertyMap)
Loads mappings from the
propertyMap into the TypeMap. |
Condition<?,?> |
getCondition()
Returns the Condition that must apply for the source and destination in order for mapping to
take place, else
null if no condition has been configured. |
Converter<S,D> |
getConverter()
Returns the Converter configured for this TypeMap, else
null if no Converter has been
configured. |
Class<D> |
getDestinationType()
Returns the destination type for the TypeMap.
|
List<Mapping> |
getMappings()
Returns a snapshot of the TypeMap's mappings.
|
String |
getName()
Returns the name of the TypeMap, else
null if the TypeMap has no name. |
Converter<S,D> |
getPostConverter()
Returns the converter to be used after mapping between the source and destination types, else
null if no post-Converter has been configured. |
Converter<S,D> |
getPreConverter()
Returns the converter to be used before mapping between the source and destination types, else
null if no post-Converter has been configured. |
Condition<?,?> |
getPropertyCondition()
Returns the Condition that must apply in properties in this TypeMap to be mapped, else
null if no condition has been configured. |
Converter<?,?> |
getPropertyConverter()
Returns the Converter used for converting properties in the TypeMap, else
null if no
Converter has been configured. |
Provider<?> |
getPropertyProvider()
Returns the Provider configured for this TypeMap, else
null if no Provider has been
configured. |
Provider<D> |
getProvider()
Returns the Provider configured for this TypeMap, else
null if no Provider has been
configured. |
Class<S> |
getSourceType()
Returns the source type for the TypeMap.
|
List<PropertyInfo> |
getUnmappedProperties()
Returns a snapshot list of destination properties that do not have mappings defined, else empty
list if all destination properties are mapped.
|
TypeMap<S,D> |
implicitMappings()
Performs implicit mapping.
|
TypeMap<S,D> |
include(Class<? super D> baseDestinationType)
Makes this TypeMap is also supporting on the mapping from
sourceType to baseDestinationType . |
<DS extends S,DD extends D> |
include(Class<DS> sourceType,
Class<DD> destinationType)
Constructs a new TypeMap derived from
this . |
<P> TypeMap<S,D> |
include(TypeSafeSourceGetter<S,P> sourceGetter,
Class<P> propertyType)
Includes
mappings from property's TypeMap. |
TypeMap<S,D> |
includeBase(Class<? super S> sourceType,
Class<? super D> destinationType)
Includes
mappings from a base TypeMap . |
D |
map(S source)
Maps
source to an instance of type D . |
void |
map(S source,
D destination)
Maps
source to destination . |
TypeMap<S,D> |
setCondition(Condition<?,?> condition)
Sets the
condition that must apply for the source and destination in order for mapping
to take place. |
TypeMap<S,D> |
setConverter(Converter<S,D> converter)
Sets the
converter to be used for any conversion requests for the TypeMap's source to
destination type. |
TypeMap<S,D> |
setPostConverter(Converter<S,D> converter)
Sets the
converter to be used after mapping between the source and destination types. |
TypeMap<S,D> |
setPreConverter(Converter<S,D> converter)
Sets the
converter to be used before mapping between the source and destination types. |
TypeMap<S,D> |
setPropertyCondition(Condition<?,?> condition)
Sets the
condition that must apply in order for properties in this TypeMap to be
mapped. |
TypeMap<S,D> |
setPropertyConverter(Converter<?,?> converter)
Sets the
converter to be used for converting properties in the TypeMap. |
TypeMap<S,D> |
setPropertyProvider(Provider<?> provider)
Sets the
provider to be used for providing instances of properties during mapping. |
TypeMap<S,D> |
setProvider(Provider<D> provider)
Sets the
provider to be used for providing instances of destination type D
during mapping. |
void |
validate()
Validates that every top level destination property is mapped to one and only one source
property, or that a
Converter was set . |
TypeMap<S,D> addMappings(PropertyMap<S,D> propertyMap)
propertyMap
into the TypeMap. Mappings defined in the
propertyMap
will override any implicit mappings for the same properties.propertyMap
- from which mappings should be loadedIllegalArgumentException
- if propertyMap
is nullConfigurationException
- if a configuration error occurs while adding mappings for the
propertyMap
Condition<?,?> getCondition()
null
if no condition has been configured.setCondition(Condition)
Converter<S,D> getConverter()
null
if no Converter has been
configured.setConverter(Converter)
List<Mapping> getMappings()
This method is part of the ModelMapper SPI.
String getName()
null
if the TypeMap has no name.Converter<S,D> getPostConverter()
null
if no post-Converter has been configured.setPostConverter(Converter)
Converter<S,D> getPreConverter()
null
if no post-Converter has been configured.setPreConverter(Converter)
Condition<?,?> getPropertyCondition()
null
if no condition has been configured.setCondition(Condition)
Converter<?,?> getPropertyConverter()
null
if no
Converter has been configured.setPropertyConverter(Converter)
Provider<?> getPropertyProvider()
null
if no Provider has been
configured.setPropertyProvider(Provider)
Provider<D> getProvider()
null
if no Provider has been
configured.setProvider(Provider)
List<PropertyInfo> getUnmappedProperties()
This method is part of the ModelMapper SPI.
D map(S source)
source
to an instance of type D
.source
- object to map fromD
IllegalArgumentException
- if source
is nullMappingException
- if an error occurs while mappingvoid map(S source, D destination)
source
to destination
.source
- object to map fromdestination
- object to map toIllegalArgumentException
- if source
or destination
are nullMappingException
- if an error occurs while mappingTypeMap<S,D> setCondition(Condition<?,?> condition)
condition
that must apply for the source and destination in order for mapping
to take place.IllegalArgumentException
- if condition
is nullTypeMap<S,D> setConverter(Converter<S,D> converter)
converter
to be used for any conversion requests for the TypeMap's source to
destination type. This converter will be used in place of any mappings that have been added to
the TypeMap.IllegalArgumentException
- if converter
is nullTypeMap<S,D> setPostConverter(Converter<S,D> converter)
converter
to be used after mapping between the source and destination types.IllegalArgumentException
- if converter
is nullTypeMap<S,D> setPreConverter(Converter<S,D> converter)
converter
to be used before mapping between the source and destination types.IllegalArgumentException
- if converter
is nullTypeMap<S,D> setPropertyCondition(Condition<?,?> condition)
condition
that must apply in order for properties in this TypeMap to be
mapped. This is overridden by any conditions defined in a PropertyMap.IllegalArgumentException
- if condition
is nullTypeMap<S,D> setPropertyConverter(Converter<?,?> converter)
converter
to be used for converting properties in the TypeMap. This is
overridden by any converters defined in a PropertyMap.IllegalArgumentException
- if converter
is nullTypeMap<S,D> setPropertyProvider(Provider<?> provider)
provider
to be used for providing instances of properties during mapping. This
is overriden by any providers defined in a PropertyMap.IllegalArgumentException
- if provider
is nullTypeMap<S,D> setProvider(Provider<D> provider)
provider
to be used for providing instances of destination type D
during mapping.IllegalArgumentException
- if provider
is nullvoid validate()
Converter
was set
. If not, a
ConfigurationException is thrown detailing any missing mappings.ValidationException
- if any TypeMaps contain unmapped properties<V> TypeMap<S,D> addMapping(SourceGetter<S> sourceGetter, DestinationSetter<D,V> destinationSetter)
TypeMap
by defining sourceGetter
-> destinationSetter
typeMap.addMapping(Src::getA, Dest::setB);
typeMap.<String>addMapping(src -> src.getC().getD(), (dest, value) -> dest.getE().setF(value))
V
- type of destination property wants to be setsourceGetter
- source property getterdestinationSetter
- destination property setterTypeMap<S,D> addMappings(ExpressionMap<S,D> mapper)
TypeMap
by defining a mapper
action
You can chain addMappings
contains only one property mapping like
typeMap.addMappings(mapper -> mapper.<String>map(Src::getA, Dest::setB))
.addMappings(mapper -> mapper.<String>skip(Dest::setB))
.addMappings(mapper -> mapper.when(condition).<String>map(Src::getA, Dest::setB))
.addMappings(mapper -> mapper.when(condition).<String>skip(Dest::setB))
.addMappings(mapper -> mapper.using(converter).<String>map(Src::getA, Dest::setB))
.addMappings(mapper -> mapper.with(provider).<String>map(Src::getA, Dest::setB));
Or you can define all property mappings in one addMappings
like
typeMap.addMappings(mapper -> {
mapper.<String>map(Src::getA, Dest::setB);
mapper.<String>skip(Dest::setB);
mapper.when(condition).<String>map(Src::getA, Dest::setB);
});
mapper
- a mapper defined a mapping action<DS extends S,DD extends D> TypeMap<S,D> include(Class<DS> sourceType, Class<DD> destinationType)
this
. The derived TypeMap will includes
all mappings
from the base TypeMap
, but will NOT include converter
,
condition
, and provider
from the base TypeMap
.DS
- derived type of source classDD
- derived type of destination classsourceType
- source typedestinationType
- destination typeIllegalArgumentException
- if TypePair.of(sourceType, destinationType)
already defined
in modelMapper.getTypeMaps()
TypeMap<S,D> include(Class<? super D> baseDestinationType)
sourceType
to baseDestinationType
.baseDestinationType
- the base destination typeIllegalArgumentException
- if TypePair.of(sourceType, baseDestinationType)
already defined
in modelMapper.getTypeMaps()
TypeMap<S,D> includeBase(Class<? super S> sourceType, Class<? super D> destinationType)
mappings
from a base TypeMap
.sourceType
- source typedestinationType
- destination typeIllegalArgumentException
- if TypePair.of(sourceType, destinationType)
already defined
in modelMapper.getTypeMaps()
<P> TypeMap<S,D> include(TypeSafeSourceGetter<S,P> sourceGetter, Class<P> propertyType)
mappings
from property's TypeMap. If we want to map Source to Destination and we already have
a TypeMap map a property of the source to destination, then we can include this property's TypeMap by
include(Source::getProperty, Property.class)
.sourceGetter
- the source getterpropertyType
- the property typeCopyright © 2011–2024. All rights reserved.