Class Mappers


  • public class Mappers
    extends Object
    Factory for obtaining mapper instances if no explicit component model such as CDI is configured via Mapper.componentModel().

    Mapper implementation types are expected to have the same fully qualified name as their interface type, with the suffix Impl appended. When using this factory, mapper types - and any mappers they use - are instantiated by invoking their public no-args constructor.

    By convention, a single instance of each mapper is retrieved from the factory and exposed on the mapper interface type by declaring a member named INSTANCE like this:

     @Mapper
     public interface CustomerMapper {
    
         CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class );
    
         // mapping methods...
     }
     
    Author:
    Gunnar Morling
    • Method Detail

      • getMapper

        public static <T> T getMapper​(Class<T> clazz)
        Returns an instance of the given mapper type.
        Type Parameters:
        T - The type of the mapper to create.
        Parameters:
        clazz - The type of the mapper to return.
        Returns:
        An instance of the given mapper type.
      • getMapperClass

        public static <T> Class<? extends T> getMapperClass​(Class<T> clazz)
        Returns the class of the implementation for the given mapper type.
        Type Parameters:
        T - The type of the mapper to create.
        Parameters:
        clazz - The type of the mapper to return.
        Returns:
        A class of the implementation for the given mapper type.
        Since:
        1.3