mapstruct / mapstruct-eclipse

An Eclipse plug-in for working with MapStruct
Other
13 stars 8 forks source link

@Qualifier behavior not working with object #35

Closed bordigoni closed 8 years ago

bordigoni commented 8 years ago

Consider the Mapper :

@GearQualifier
public abstract class GearSpecMapper {

   @GearDTO1Qualifier
   public GearDTO1 toDTO1(GearSpec entity) {
     return ... // some mapping logic
   }

   @GearDTO2Qualifier
   public GearDTO2 toDTO2(GearSpec entity) {
     return ... // some mapping logic
   }

}

And my main mapper

@Mapper(uses=GearQualifier.class)
public interface GearSpecMapper {

  @Mapping(target="gearDTO", source="gear", qualifiedBy={GearQualifier.class, GearDTO1Qualifier.class})
   EngineDTO1 fromEntity(Entity entity);

}

All my @Gear*Qualifier are @Qualifier with propeper retention

I get an error saying my mapping is ambigious and he quotes that he cannot choose beetween the two method of my GearSpecMapper

In the documentation the only example shown with @Qualifier is used mapping a String to a String. Is using this a limitation (no mapping object supported )? Did I miss something. I used a decorator as a workaround.

Cheers,

PS : love the framework otherwise ;-), great work !

agudian commented 8 years ago

Hi @bordigoni,

this repository and the issues are meant for the Eclipse plugin that give some assistence for working with the MapStruct annotations. Your question would better be suited on the mapstruct-users mailing list, bugs and feature requests regarding the mapstruct itself are handled in https://github.com/mapstruct/mapstruct.

That all said, try @Mapper(uses = GearSpecMapper.class). The uses attribute is there to list other mappers, converters, factories, etc that may be used map certain types or to create certain types.

I'm closing the issue here now. If it doesn't help you, please move the discussion over to the mailing list. Or file a bug in the mapstruct-repository (I'm pretty sure though that this feature generally works - but who knows... :wink:)

Thanks!

PS: especially thanks for the praise! :)