-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
Expected behavior
If you have a class with hierarchy and multiple AfterMapping methods with the same name but for different level of the hierarchy, mapstruct should generate only one method call, because the overloaded method can not be reached
Actual behavior
Mapstruct handles both methods individual and did not recognize that the overloaded method can not be reached. It results in a duplicated call to the same method
Steps to reproduce the problem
public class Entity {
long id;
String name;
}
public interface ParentDTOInterface {
long getId();
}
@Data
public class ParentDTO implements ParentDTOInterface {
private long id;
}
@Data
public class ChildDTO extends ParentDTO {
private String name;
}
public interface Mapper {
ParentDTO mapParent(Entity entity);
ChildDTO mapChild(Entity entity);
@AfterMapping
default void after(@MappingTarget ParentDTOInterface dto, Entity entity) {
}
@AfterMapping
default void after(@MappingTarget ChildDTO childDTO, Entity entity) {
}
}
generated child related code:
@Override
ChildDTO map(Entity entity) {
ChildDTO childDTO = new ChildDTO();
childDTO.setId(entity.getId());
childDTO.setName(entity.getName());
after(childDTO, entity);
after(childDTO, entity); <---- this is the bug :)
}
generated parent related code:
@Override
ParentDTO map(Entity entity) {
ParentDTO parentDTO = new ParentDTO();
parentDTO.setId(entity.getId());
after(parentDTO, entity);
}
MapStruct Version
1.6.3
Reactions are currently unavailable