1

I have some trouble with MapStruct using abstract class. I have 2 mappers:

MapperA extends AbstractMapper<U,V>
MapperB extends AbstractMapper<U,V>

MapperA uses MapperB

I have a method in AbstractMapper

public <T extends AbstractReference> T resolveReference(String id, @TargetType Class<T> entityClass) {
    // Some implementation
}

While clean install, i got the ambiguous method error.

It seems that Mapstruct find the method twice, one frome each Mapper that extends the same class.

I did some search on the qualifier thing but it seems usefull when using different methods with the same signature. But in my case, it's the same one!!

If you have any ints.

Thanks

Edit:

    @Mapper(componentModel = "cdi", uses = {MapperB.class}) 
    @ApplicationScoped 
    public abstract class MapperA extends AbstractMapper<U1,V1> {} 

MapperB does not use any other mapper.

    @Mapper(componentModel = "cdi")
    @ApplicationScoped
    public abstract class MapperB extends AbstractMapper<U2,V2> {}
4

1 回答 1

2

你实际上没有一种方法,你有两种方法。一进MapperA一进MapperB。MapStruct 不关心继承和每个方法所在的位置。

还有你的方法

public <T extends AbstractReference> T resolveReference(String id, @TargetType Class<T> entityClass) {
    // Some implementation
}

是具有相同擦除且不依赖于AbstractMapper泛型参数的泛型,这导致MapStruct的模棱两可的方法错误。

我不确定您在该方法中实际上在做什么。但是,如果它是不依赖于AbstractMapper泛型参数U的泛型V,那么我建议您将此方法提取到不同的类并将该类添加到uses注释变量中。

如果方法依赖于参数然后确保它们是它的一部分,那么 MapStruct 将正常工作,因为它们在编译期间将具有不同的类型(U1, V1U2, V2

于 2017-02-01T18:21:34.110 回答