I'm using mapstruct to map hibernate entities to DTO's and the inverse.
The mappings are working very well, however I'm still struggling with lazy/eager mappings.
In some cases I want to map a lighter version of the entity (without fetching collections). In some other cases I want to map fetching some of the collections.
To do that I was thinking to use different versions of mappings, ignoring the collections when I don't want to fetch.
I try to do that using custom qualifiers: @LazyMapping and @EagerMapping
@EagerMapping
@Mappings({
@Mapping(target = "description", source = "sampleNested.description"),
@Mapping(target = "attributes", source = "sampleNested.attributes"),
@Mapping(target = "somecollection", source = "collectionxpto") })
SampleDTO sampleDtoToEntity(SampleEntity sampleEntity);
@LazyMapping
@InheritConfiguration
@Mapping(target = "somecollection", ignore = true) //MARK AS IGNORED
SampleDTO lazySampleDtoToEntity(SampleEntity sampleEntity);
@IterableMapping(qualifiedBy=EagerMapping.class)
List<SampleDTO> samplesDtoToEntities(List<SampleEntity> sampleEntities);
@IterableMapping(qualifiedBy=LazyMapping.class)
List<SampleDTO> lazySamplesDtoToEntities(List<SampleEntity> sampleEntities);
However in some cases I'm getting error for ambiguos mappings.
Is this the correct approach? How can I do this with mapstruct?
Thank you