Annotation Type MapMapping
Example:
@Mapper
public interface SimpleMapper {
@MapMapping(valueDateFormat = "dd.MM.yyyy")
Map<String, String> longDateMapToStringStringMap(Map<Long, Date> source);
}
// generates
public class SimpleMapperImpl implements SimpleMapper {
@Override
public Map<String, String> longDateMapToStringStringMap(Map<Long, Date> source) } {
Map<String, String> map = new HashMap<String, String>(); }
for ( java.util.Map.Entry<Long, Date> entry : source.entrySet() ) } {
String key = new DecimalFormat( "" ).format( entry.getKey() );
String value = new SimpleDateFormat( "dd.MM.yyyy" ).format( entry.getValue() );
map.put( key, value );
}
// ...
}
}
NOTE: at least one element needs to be specified
- Author:
- Gunnar Morling
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionA format string as processable bySimpleDateFormatif the annotated method maps from a map with key typeStringto an map with key typeDateor vice-versa.Class<? extends Annotation> Allows detailed control over the key mapping process.A format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa.Class<? extends Annotation>[]A key value 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 map mapping method's key 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.Class<?> Specifies the type of the key to be used in the result of the mapping method in case multiple mapping methods qualify.Specifies the locale to be used when processingSimpleDateFormatorDecimalFormatfor key or value mappings in maps.The strategy to be applied whennullis passed as source value to this map mapping.A format string as processable bySimpleDateFormatif the annotated method maps from a map with value typeStringto an map with value typeDateor vice-versa.Class<? extends Annotation> Allows detailed control over the value mapping process.A format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa.Class<? extends Annotation>[]A value qualifier can be specified to aid the selection process of a suitable mapper for the values in the map.String[]String-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's value 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.Class<?> Specifies the type of the value to be used in the result of the mapping method in case multiple mapping methods qualify.
-
Element Details
-
keyDateFormat
String keyDateFormatA format string as processable bySimpleDateFormatif the annotated method maps from a map with key typeStringto an map with key typeDateor vice-versa. Will be ignored for all other key types.If the
locale()is 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:
""
-
valueDateFormat
String valueDateFormatA format string as processable bySimpleDateFormatif the annotated method maps from a map with value typeStringto an map with value typeDateor vice-versa. Will be ignored for all other value types.If the
locale()is 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:
""
-
keyNumberFormat
String keyNumberFormatA format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa. Will be ignored for all other key types.If the
locale()is specified, the number format will be applied in the context of the given locale. Otherwise, the system's default locale will be used.- Returns:
- A decimal format string as processable by
DecimalFormat. - See Also:
- Default:
""
-
valueNumberFormat
String valueNumberFormatA format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa. Will be ignored for all other value types.If the
locale()is specified, the number format will be applied in the context of the given locale. Otherwise, the system's default locale will be used.- Returns:
- A decimal format string as processable by
DecimalFormat. - See Also:
- Default:
""
-
locale
String localeSpecifies the locale to be used when processingSimpleDateFormatorDecimalFormatfor key or value mappings in maps. 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 in maps.
- Default:
""
-
keyQualifiedBy
Class<? extends Annotation>[] keyQualifiedByA key value 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:
{}
-
keyQualifiedByName
String[] keyQualifiedByNameString-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's key 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:
{}
-
valueQualifiedBy
Class<? extends Annotation>[] valueQualifiedByA value qualifier can be specified to aid the selection process of a suitable mapper for the values in the map. 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:
{}
-
valueQualifiedByName
String[] valueQualifiedByNameString-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's value 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:
{}
-
keyTargetType
Class<?> keyTargetTypeSpecifies the type of the key to be used in the result of the mapping method in case multiple mapping methods qualify.- Returns:
- the resultType to select
- Default:
void.class
-
valueTargetType
Class<?> valueTargetTypeSpecifies the type of the value to be used in the result of the mapping method in case multiple mapping methods qualify.- Returns:
- the resultType to select
- Default:
void.class
-
nullValueMappingStrategy
NullValueMappingStrategy nullValueMappingStrategyThe strategy to be applied whennullis passed as source value to this map 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
-
keyMappingControl
Class<? extends Annotation> keyMappingControlAllows detailed control over the key mapping process.- Returns:
- the mapping control
- Since:
- 1.4
- See Also:
- Default:
org.mapstruct.control.MappingControl.class
-
valueMappingControl
Class<? extends Annotation> valueMappingControlAllows detailed control over the value mapping process.- Returns:
- the mapping control
- Since:
- 1.4
- See Also:
- Default:
org.mapstruct.control.MappingControl.class
-