Skip to content

Missing import in generated mapper when referencing a nested enum from an unrelated class #2945

@bgK

Description

@bgK

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions