mapstruct / mapstruct/mapstruct
Kotlin: Issue when mapping primitive parameters
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I didn't have time to create a minimal example and compare Java/Kotlin but if you have a method like this:
Kotlin:
@Mapping(target = "nested.myFlag", source = "someFlag")
fun map(irrelevant: Source, Boolean someFlag): Target
Java:
public class Target {
public Nested nested;
}
public class Nested {
public Boolean myFlag;
}
Mapstruct will fail with:
Can't map parameter "boolean someFlag" to "Nested nested". Consider to declare/implement a mapping method: "Nested map(boolean value)".
- The message isn't exactly correct, it should rather be:
Can't map parameter "boolean someFlag" to "Boolean myFlag". Consider to declare/implement a mapping method: "Boolean map(boolean value)". - I would expect MapStruct to have no problem mapping a primitive
booleanto a wrapperBoolean(might be related to Kotlin vs. Java Boolean) - If I'm not mistaken, this works when both booleans are in the source/target objects but not when the source boolean is a method parameter
This does not work:
fun map(boolean: Boolean): Boolean? = boolean
Workaround (nullable Boolean):
@Mapping(target = "nested.myFlag", source = "someFlag")
fun map(irrelevant: Source, Boolean? someFlag): Target
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 by reproducing the Kotlin mapper signature with a primitive Boolean parameter and compare it with the equivalent Java case described in the issue. Confirm whether the parameter is resolved to the nested Boolean target and whether the diagnostic names Boolean myFlag; done means the behavior and error message match the expected primitive-to-wrapper mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100