Interface GenericMapper<T,ResponseDTO,RequestDTO>

All Known Subinterfaces:
IAdvertiserMapper, IPermissionMapper, IProfileMapper, IRoleMapper, IUserMapper
All Known Implementing Classes:
AdvertiserMapperImpl, PermissionMapperImpl, ProfileMapperImpl, RoleMapperImpl, UserMapperImpl

public interface GenericMapper<T,ResponseDTO,RequestDTO>
A generic mapper interface to facilitate conversion between entities, request DTOs, and response DTOs.

This interface defines methods for:

  • Converting a single entity to a response DTO.
  • Converting a request DTO to an entity.
  • Mapping a collection of entities to a list of response DTOs.
  • Converting a Spring Data Page of entities into a Page of response DTOs, handling null or empty cases gracefully.
By standardizing these operations, implementations can reduce boilerplate code and ensure consistency across data transformation layers.
  • Method Summary

    Modifier and Type
    Method
    Description
    toEntity(RequestDTO requestDTO)
    Converts a request DTO into an entity instance.
    Converts a collection of entities into a list of response DTOs.
    default org.springframework.data.domain.Page<ResponseDTO>
    toPageResponseDTO(org.springframework.data.domain.Page<T> entities)
    Converts a paginated list of entities into a paginated list of response DTOs.
    toResponseDTO(T entity)
    Converts an entity instance to its corresponding response DTO.
  • Method Details

    • toResponseDTO

      ResponseDTO toResponseDTO(T entity)
      Converts an entity instance to its corresponding response DTO.
      Parameters:
      entity - the domain entity
      Returns:
      a response DTO representing the entity
    • toEntity

      T toEntity(RequestDTO requestDTO)
      Converts a request DTO into an entity instance.
      Parameters:
      requestDTO - the incoming request data
      Returns:
      a domain entity constructed from the request DTO
    • toListResponseDTO

      List<ResponseDTO> toListResponseDTO(Collection<T> entities)
      Converts a collection of entities into a list of response DTOs.
      Parameters:
      entities - a collection of domain entities
      Returns:
      a list of corresponding response DTOs
    • toPageResponseDTO

      default org.springframework.data.domain.Page<ResponseDTO> toPageResponseDTO(org.springframework.data.domain.Page<T> entities)
      Converts a paginated list of entities into a paginated list of response DTOs. If the source page is null or empty, returns an empty, unpaged page.
      Parameters:
      entities - a Page of domain entities
      Returns:
      a Page of response DTOs preserving paging metadata