Mapstruct : Ambiguous mapping methods found for mapping collection element

santhosh picture santhosh · Mar 15, 2018 · Viewed 7.8k times · Source

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

Answer

ihebiheb picture ihebiheb · Apr 23, 2019

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)