@Target(value=METHOD) @Retention(value=CLASS) public @interface IterableMapping
List<String>
and List<Date>
.
Note: either dateFormat()
, elementTargetType()
or qualifiedBy()
must be specified
Example: Convert List<Float> to List<String>
@Mapper
public interface FloatToStringMapper {
@IterableMapping( numberFormat = "##.00" )
List<String> sourceToTarget(List<Float> source);
}
// generates
public class FloatToStringMapperImpl implements FloatToStringMapper {
@Override
public List<String> sourceToTarget(List<Float> source) {
List<String> list = new ArrayList<String>( source.size() );
for ( Float float1 : source ) {
list.add( new DecimalFormat( "##.00" ).format( float1 ) );
}
// ...
}
}
Supported mappings are:
Iterable<A>
to/from Iterable<B>
/Iterable<A>
Iterable<A>
to/from B[]
/A[]
Iterable<A>
to/from Stream<B>
/Stream<A>
A[]
to/from Stream<B>
/Stream<A>
A[]
to/from B[]
Stream<A>
to/from Stream<B>
Modifier and Type | Optional Element and Description |
---|---|
String |
dateFormat
A format string as processable by
SimpleDateFormat if the annotated method maps from an iterable of
String to an iterable Date or vice-versa. |
Class<? extends Annotation> |
elementMappingControl
Allows detailed control over the mapping process.
|
Class<?> |
elementTargetType
Specifies the type of the element to be used in the result of the mapping method in case multiple mapping
methods qualify.
|
NullValueMappingStrategy |
nullValueMappingStrategy
The strategy to be applied when
null is passed as source value to this iterable mapping. |
String |
numberFormat
A format string as processable by
DecimalFormat if the annotated method maps from a
Number to a String or vice-versa. |
Class<? extends Annotation>[] |
qualifiedBy
A qualifier can be specified to aid the selection process of a suitable mapper.
|
String[] |
qualifiedByName
String-based form of qualifiers; When looking for a suitable mapping method to map this iterable mapping method's
element type, MapStruct will only consider those methods carrying directly or indirectly (i.e. on the
class-level) a
Named annotation for each of the specified qualifier names. |
public abstract String dateFormat
SimpleDateFormat
if the annotated method maps from an iterable of
String
to an iterable Date
or vice-versa. Will be ignored for all other element types.SimpleDateFormat
.public abstract String numberFormat
DecimalFormat
if the annotated method maps from a
Number
to a String
or vice-versa. Will be ignored for all other element types.DecimalFormat
.public abstract Class<? extends Annotation>[] qualifiedBy
Qualifier
public abstract String[] qualifiedByName
Named
annotation for each of the specified qualifier names.
Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large number of qualifiers as no custom annotation types are needed.
qualifiedBy()
,
Named
public abstract Class<?> elementTargetType
public abstract NullValueMappingStrategy nullValueMappingStrategy
null
is passed as source value to this iterable mapping. If no
strategy is configured, the strategy given via MapperConfig.nullValueMappingStrategy()
or
Mapper.nullValueMappingStrategy()
will be applied, using NullValueMappingStrategy.RETURN_NULL
by default.null
is passed as source value to the methods of this mapping.public abstract Class<? extends Annotation> elementMappingControl
DeepClone
,
NoComplexMapping
,
MappingControl
Copyright © 2012-2021 MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.