Package org.mapstruct

Annotation Type MapMapping


  • @Target(METHOD)
    @Retention(CLASS)
    public @interface MapMapping
    Configures 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

    Author:
    Gunnar Morling
    • Element Detail

      • keyDateFormat

        String keyDateFormat
        A format string as processable by SimpleDateFormat if the annotated method maps from a map with key type String to an map with key type Date or vice-versa. Will be ignored for all other key types.
        Returns:
        A date format string as processable by SimpleDateFormat.
        Default:
        ""
      • valueDateFormat

        String valueDateFormat
        A format string as processable by SimpleDateFormat if the annotated method maps from a map with value type String to an map with value type Date or vice-versa. Will be ignored for all other value types.
        Returns:
        A date format string as processable by SimpleDateFormat.
        Default:
        ""
      • keyNumberFormat

        String keyNumberFormat
        A format string as processable by DecimalFormat if the annotated method maps from a Number to a String or vice-versa. Will be ignored for all other key types.
        Returns:
        A decimal format string as processable by DecimalFormat.
        Default:
        ""
      • valueNumberFormat

        String valueNumberFormat
        A format string as processable by DecimalFormat if the annotated method maps from a Number to a String or vice-versa. Will be ignored for all other value types.
        Returns:
        A decimal format string as processable by DecimalFormat.
        Default:
        ""
      • keyQualifiedBy

        Class<? extends 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

        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) a 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.

        Returns:
        One or more qualifier name(s)
        See Also:
        keyQualifiedBy(), Named
        Default:
        {}
      • valueQualifiedBy

        Class<? extends 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

        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) a 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.

        Returns:
        One or more qualifier name(s)
        See Also:
        valueQualifiedBy(), Named
        Default:
        {}
      • keyTargetType

        Class<?> keyTargetType
        Specifies 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<?> valueTargetType
        Specifies 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