• @Target(METHOD)
    @Retention(CLASS)
    public @interface EnumMapping

    Configured the mapping between two value types.

    Example: Using a suffix for enums

    
     public enum CheeseType {
         BRIE,
         ROQUEFORT
     }
    
     public enum CheeseTypeSuffixed {
         BRIE_TYPE,
         ROQUEFORT_TYPE
     }
    
     @Mapper
     public interface CheeseMapper {
    
         @EnumMapping(nameTransformationStrategy = "suffix", configuration = "_TYPE")
         CheeseTypeSuffixed map(Cheese cheese);
    
         @InheritInverseConfiguration
         Cheese map(CheeseTypeSuffixed cheese);
    
     }
     
    
     // generates
     public class CheeseMapperImpl implements CheeseMapper {
    
         @Override
         public CheeseTypeSuffixed map(Cheese cheese) {
             if ( cheese == null ) {
                 return null;
             }
    
             CheeseTypeSuffixed cheeseTypeSuffixed;
    
             switch ( cheese ) {
                 case BRIE:
                     cheeseTypeSuffixed = CheeseTypeSuffixed.BRIE_TYPE;
                     break;
                 case ROQUEFORT:
                     cheeseTypeSuffixed = CheeseTypeSuffixed.ROQUEFORT_TYPE;
                     break;
                 default:
                     throw new IllegalArgumentException( "Unexpected enum constant: " + cheese );
             }
    
             return cheeseTypeSuffixed;
         }
    
         @Override
         public Cheese map(CheeseTypeSuffixed cheese) {
             if ( cheese == null ) {
                 return null;
             }
    
             CheeseType cheeseType;
    
             switch ( cheese ) {
                 case BRIE_TYPE:
                     cheeseType = CheeseType.BRIE;
                     break;
                 case ROQUEFORT_TYPE:
                     cheeseType = CheeseType.ROQUEFORT;
                     break;
                 default:
                     throw new IllegalArgumentException( "Unexpected enum constant: " + cheese );
             }
    
             return cheeseType;
         }
     }
     
    Since:
    1.4
    Author:
    Filip Hrisafov
      • configuration

        String configuration

        The configuration that should be passed on the appropriate name transformation strategy. e.g. a suffix that should be applied to the source enum when doing name based mapping.

        Returns:
        the configuration to use
        Default:
        ""
      • unexpectedValueMappingException

        Class<? extends Exception> unexpectedValueMappingException
        Returns:
        the exception that should be used in the generated code
        Default:
        java.lang.IllegalArgumentException.class