mapstruct
mapstruct copied to clipboard
Missing import in generated mapper when referencing a nested enum from an unrelated class
Given a nested enumeration,
public class TestEnumHolder {
public enum TestEnum {
VALUE_1,
VALUE_2;
}
}
A source class (record for brievty),
public record TestEntity(String testProperty) {}
A target class,
public class TestDTO {
private TestEnumHolder.TestEnum testProperty;
public TestEnumHolder.TestEnum getTestProperty() {
return testProperty;
}
public void setTestProperty(TestEnumHolder.TestEnum testProperty) {
this.testProperty = testProperty;
}
}
A mapper,
@Mapper
public interface TestMapper {
TestDTO map(TestEntity entity);
}
When compiling the mapper with Mapstruct 1.5.2, the following error occurs:
TestMapperImpl.java:[23,66] package TestEnumHolder does not exist
When inspecting the generated mapper source, the import is missing for the enum. This used to work with Mapstruct 1.4.1.
This is the reproduction case packaged as a Maven project: mapstruct-nested-enum-repro.zip
Thanks for reporting this @bgK. This is similar to #2897, but in another area.
It seems like our approach of not using nested imports is a bit buggy. We most likely need to reverse that change.