How to map extended DTO's from same source class

Well, this turned out to be a simple fix, it was indeed a missing configuration issue. What was missing was the @IterableMapping annotation.

Once I set the elementTargetType to the correct types, everything worked as expected.

The correct Mapper code

@Mapper(uses = { CommentMapper.class })
public interface TicketMapper {
    TicketDTO mapToTicketDTO(Ticket ticket);

    @IterableMapping(elementTargetType = TicketDTO.class)
    List<TicketDTO> mapToTicketDTOList(Collection<Ticket> tickets);

    TicketWithCommentsDTO mapToTicketWithCommentsDTO(Ticket ticket);

    @IterableMapping(elementTargetType = TicketWithCommentsDTO.class)
    List<TicketWithCommentsDTO> mapToTicketWithCommentDTOList(Collection<Ticket> tickets);
}

Tags:

Java

Mapstruct