Package org.mapstruct
Annotation Type MapMapping
-
@Target(METHOD) @Retention(CLASS) public @interface MapMappingConfigures the mapping between two map types, e.g. Map<String, String> and Map<Long, Date>.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
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.StringkeyDateFormatA format string as processable bySimpleDateFormatif the annotated method maps from a map with key typeStringto an map with key typeDateor vice-versa.java.lang.Class<? extends java.lang.annotation.Annotation>keyMappingControlAllows detailed control over the key mapping process.java.lang.StringkeyNumberFormatA format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa.java.lang.Class<? extends java.lang.annotation.Annotation>[]keyQualifiedByA key value qualifier can be specified to aid the selection process of a suitable mapper.java.lang.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.java.lang.Class<?>keyTargetTypeSpecifies the type of the key to be used in the result of the mapping method in case multiple mapping methods qualify.NullValueMappingStrategynullValueMappingStrategyThe strategy to be applied whennullis passed as source value to this map mapping.java.lang.StringvalueDateFormatA format string as processable bySimpleDateFormatif the annotated method maps from a map with value typeStringto an map with value typeDateor vice-versa.java.lang.Class<? extends java.lang.annotation.Annotation>valueMappingControlAllows detailed control over the value mapping process.java.lang.StringvalueNumberFormatA format string as processable byDecimalFormatif the annotated method maps from aNumberto aStringor vice-versa.java.lang.Class<? extends java.lang.annotation.Annotation>[]valueQualifiedByA value qualifier can be specified to aid the selection process of a suitable mapper for the values in the map.java.lang.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.java.lang.Class<?>valueTargetTypeSpecifies the type of the value to be used in the result of the mapping method in case multiple mapping methods qualify.
-
-
-
Element Detail
-
keyDateFormat
java.lang.String keyDateFormat
A 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.- Returns:
- A date format string as processable by
SimpleDateFormat.
- Default:
- ""
-
-
-
valueDateFormat
java.lang.String valueDateFormat
A 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.- Returns:
- A date format string as processable by
SimpleDateFormat.
- Default:
- ""
-
-
-
keyQualifiedBy
java.lang.Class<? extends java.lang.annotation.Annotation>[] keyQualifiedBy
A 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:
Qualifier
- Default:
- {}
-
-
-
keyQualifiedByName
java.lang.String[] keyQualifiedByName
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.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:
keyQualifiedBy(),Named
- Default:
- {}
-
-
-
valueQualifiedBy
java.lang.Class<? extends java.lang.annotation.Annotation>[] valueQualifiedBy
A 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:
Qualifier
- Default:
- {}
-
-
-
valueQualifiedByName
java.lang.String[] valueQualifiedByName
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.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:
valueQualifiedBy(),Named
- Default:
- {}
-
-
-
nullValueMappingStrategy
NullValueMappingStrategy nullValueMappingStrategy
The 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:
- org.mapstruct.NullValueMappingStrategy.RETURN_NULL
-
-
-
keyMappingControl
java.lang.Class<? extends java.lang.annotation.Annotation> keyMappingControl
Allows detailed control over the key mapping process.- Returns:
- the mapping control
- Since:
- 1.4
- See Also:
DeepClone,NoComplexMapping,MappingControl
- Default:
- org.mapstruct.control.MappingControl.class
-
-
-
valueMappingControl
java.lang.Class<? extends java.lang.annotation.Annotation> valueMappingControl
Allows detailed control over the value mapping process.- Returns:
- the mapping control
- Since:
- 1.4
- See Also:
DeepClone,NoComplexMapping,MappingControl
- Default:
- org.mapstruct.control.MappingControl.class
-
-