Skip to content

Not using kotlin primary constructor #2577

@HKITYAN

Description

@HKITYAN

i am developing project using kotlin and have the following classes
DTO class

data class TestDTO (
    val name: String,
    val type: String
)

Model class

@Entity
data class Test (
    @Column(name = "name")
    val name: String? = null,

    @Column(name = "type")
    val type: String? = null,

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "BIGINT")
    val id: BigInteger? = null
)

Mapper Class

@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
interface TestMapper {
    fun convertToTest(testDTO: TestDTO): Test
}

I expected the generated mapper will use constructor to create the Test class (the model), but the result is like below

@Component
public class TestMapperImpl implements TestMapper {

    @Override
    public Test convertToTest(TestDTO testDTO) {
        if ( testDTO == null ) {
            return null;
        }

        Test test = new Test();

        return test;
    }
}

why is it using the empty constructor of Test, can we use the Test(name, type) constructor?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions