javamapstruct

Mapstruct : Ambiguous mapping methods found for mapping collection element


I have two methods for mapping entity to domain.

RDomain entityToDomain(REntity rEntity)

/*
this method ignores some of the fields in the domain.
*/
RDomain entityToDomainLight(REntity rEntity)

I'm getting Ambiguous mapping methods found for mapping collection element when I try to define mapping method for List of entities to domains.

List<RDomain> entitiesToDomains(List<REntity> rEntities)

Is there a way to define which method to use for mapping collection of objects


Solution

  • As @Filip suggested, it is better to do something like that :

    RDomain entityToDomain(REntity rEntity)
    
    @Named(value = "useMe")
    RDomain entityToDomainLight(REntity rEntity)
    
    @IterableMapping(qualifiedByName = "useMe")
    List<RDomain> entitiesToDomains(List<REntity> rEntities)