mapstruct / mapstruct/mapstruct

Kotlin: Issue when mapping primitive parameters

Open
#2,365 0 comments 6 reactions 0 assignees View on GitHub

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)".
  1. 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)".
  2. I would expect MapStruct to have no problem mapping a primitive boolean to a wrapper Boolean (might be related to Kotlin vs. Java Boolean)
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.