Pashchenko Denis :
I use 2 libraries in my project which require mappers with the different interfaces:
public interface FirstLibraryMapper<T, M> {
M mapToDto(T domain);
List<M> mapToDto(List<T> domains);
}
public interface SecondLibraryMapper<T, M> {
M mapToDto(T domain);
}
I want to create a single mapper bean using mapstruct that will be injected in libraries components by interface because both interfaces have a method with exact signature:
@Mapper
public interface MyMapper extends FirstLibraryMapper<MyDomain, MyDto>, SecondLibraryMapper<MyDomain, MyDto> {
}
When I try to compile, I get this error:
Ambiguous mapping methods found for mapping collection element to MyDto: MyDto mapToDto(MyDomain arg0), MyDto mapToDto(MyDomain arg0).
I was able to bypass this issue by using @Named and @IterableMapping but it feels wrong and clunky. Why can't mapstruct processor ignore the second method if it has an exact signature as the first one? Should I rise an issue on their github page? Or am I wrong in that case?
Pashchenko Denis :
Problem solved by overriding method in result mapper which is still a bit clunky but seems to do the trick.
@Mapper
public interface MyMapper extends FirstLibraryMapper<MyDomain, MyDto>, SecondLibraryMapper<MyDomain, MyDto> {
@Override
MyDto mapToDto(MyDomain domain);
}
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=415903&siteId=1