Annotation Type 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/fromIterable<B>/Iterable<A>Iterable<A>to/fromB[]/A[]Iterable<A>to/fromStream<B>/Stream<A>A[]to/fromStream<B>/Stream<A>A[]to/fromB[]Stream<A>to/fromStream<B>
- Author:
- Gunnar Morling
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionA format string as processable bySimpleDateFormatif the annotated method maps from an iterable ofStringto an iterableDateor vice-versa.Class<? extends Annotation> Allows detailed control over the mapping process.Class<?> Specifies the type of the element to be used in the result of the mapping method in case multiple mapping methods qualify.Specifies the locale to be used when processingdateFormat()ornumberFormat().The strategy to be applied whennullis passed as source value to this iterable mapping.A format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa.Class<? extends Annotation>[]A qualifier can be specified to aid the selection process of a suitable mapper.String[]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) aNamedannotation for each of the specified qualifier names.
-
Element Details
-
dateFormat
String dateFormatA format string as processable bySimpleDateFormatif the annotated method maps from an iterable ofStringto an iterableDateor vice-versa. Will be ignored for all other element types.If the
locale()is also specified, the format will consider the specified locale when processing the date. Otherwise, the system's default locale will be used.- Returns:
- A date format string as processable by
SimpleDateFormat. - See Also:
- Default:
""
-
numberFormat
String numberFormatA format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa. Will be ignored for all other element types.If the
locale()is also specified, the number format will be applied in the context of the given locale. Otherwise, the system's default locale will be used to process the number format.- Returns:
- A decimal format string as processable by
DecimalFormat. - See Also:
- Default:
""
-
locale
String localeSpecifies the locale to be used when processingdateFormat()ornumberFormat().The locale should be a plain tag representing the language, such as "en" for English, "de" for German, etc.
If no locale is specified, the system's default locale will be used.
- Returns:
- A string representing the locale to be used when formatting dates or numbers.
- Default:
""
-
qualifiedBy
Class<? extends Annotation>[] qualifiedByA qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple mappers (hand written of internal) qualify and result in an 'Ambiguous mapping methods found' error. A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method.- Returns:
- the qualifiers
- See Also:
- Default:
{}
-
qualifiedByName
String[] qualifiedByNameString-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) aNamedannotation 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.
- Returns:
- One or more qualifier name(s)
- See Also:
- Default:
{}
-
elementTargetType
Class<?> elementTargetTypeSpecifies the type of the element to be used in the result of the mapping method in case multiple mapping methods qualify.- Returns:
- the elementTargetType to select
- Default:
void.class
-
nullValueMappingStrategy
NullValueMappingStrategy nullValueMappingStrategyThe strategy to be applied whennullis passed as source value to this iterable mapping. If no strategy is configured, the strategy given viaMapperConfig.nullValueMappingStrategy()orMapper.nullValueMappingStrategy()will be applied, usingNullValueMappingStrategy.RETURN_NULLby default.- Returns:
- The strategy to be applied when
nullis passed as source value to the methods of this mapping.
- Default:
RETURN_NULL
-
elementMappingControl
Class<? extends Annotation> elementMappingControlAllows detailed control over the mapping process.- Returns:
- the mapping control
- Since:
- 1.4
- See Also:
- Default:
org.mapstruct.control.MappingControl.class
-