mapstruct / mapstruct/mapstruct
Error “constructor ... in class ... cannot be applied to given types” while mapping with enum in the constructor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I have an issue with MapStruct when converting entity class into the DTO. This issue occur only when I have enum in the DTO's constructor.
Here is my DTO class
class ResourceDto(
val id: Long,
val name: String,
val status: ResourceStatus,
val location: LocationDto,
)
and error that I am getting while building
constructor ResourceDto in class ResourceDto cannot be applied to given types; ResourceDto resourceDto = new ResourceDto(); ^ required: long,String,ResourceStatus,LocationDto found: no arguments reason: actual and formal argument lists differ in length
When I remove the enum ResourceStatus from the constructor, it works as expected. Do you have any suggestion, why is this happening?
I am using mapstruct version 1.4.2.Final and Kotlin 1.5.10 with Spring Boot
Thanks a lot!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Kotlin ResourceDto constructor and the generated Java mapper reported by the compiler, using MapStruct 1.4.2.Final and Kotlin 1.5.10. Reproduce the mapping with and without ResourceStatus, then inspect the generated constructor call. Done means identifying whether the enum case is a MapStruct or Kotlin interop defect and documenting a confirmed result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100