Skip to content

Ambiguous mapping methods found for mapping property error on @Qualifier with the same method type #2549

Description

@learning-new-things

Raising this issue as mentioned: https://stackoverflow.com/questions/68766859/fix-for-ambiguous-mapping-methods-found-for-mapping-property-error-on-qualifier#comment121545648_68767875

This triggers ambiguous mapping methods found for mapping property error on versions 1.3.1.Final and 1.4.2.Final

@Mapper( uses = MappingUtil.class )
public interface SourceTargetMapper {

    SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class );

    @Mapping(source = "map", target = "aProperty", qualifiedBy = A.class )
    @Mapping(source = "map", target = "bProperty", qualifiedBy = B.class )
    Target toTarget(Map<String,Map<String, Object>> map);
}


public class MappingUtil {

    @Qualifier
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.CLASS)
    public @interface A {
    }
  
    @Qualifier
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.CLASS)
    public @interface B {
    }
  
    @A
    public String abc(Map<String,Map<String, Object>> in) {
       return (String) in.get("first_key").get("a_second_key");
    }
  
    @B
    public String xyz(Map<String,Map<String, Object>> in) {
       return (String) in.get("first_key").get("b_second_key");
    }
}

When I change either @A or @B to a different type, the error goes away

  @B
  public int xyz(Map<String,Map<String, Object>> in) {
     return (int) in.get("first_key").get("b_second_key");
  }

Current fix was to use the proposed alternative solution of using qualifiedByName and @nAmed instead of creating a separate utility class

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions