Skip to content

Lombok @Value/@Builder mapping fails when source/target has nested properties  #2348

@dan-lind

Description

@dan-lind

This issue is somewhat involved to explain, so I took the lombok example from the mapstruct-examples repo and adapted a bit to create a repro which can be found here: https://github.com/dan-lind/mapstruct-lombok-example

What I have observed is that when annotating the target with @value and @builder, mapstruct is unable create a mappping when the source has properties on multiple levels, and the target has nested properties.

When building the above repro code with gradle clean build, I get these error messages

SourceTargetMapper.java:23: error: Property "testingToo" has no write accessor in NestedTarget for target name SourceTargetMapper.java:23: error: Property "testing" has no write accessor in NestedTarget for target name 

The source looks like this

@Data
public class Source {
    private String test;
    private AnotherSource testToo;
}

@Data
public class AnotherSource {
    private String test;
}

and target

@Value
@Builder
public class Target {
    NestedTarget nestedTarget;
}

@Value
@Builder
public class NestedTarget {

    Long testing;
    Long testingToo;
}

Some observations: If I remove either of the source properties, i.e.

    //private String test;
    private AnotherSource testToo;

or

    private String test;
    //private AnotherSource testToo;

and make the appropriate adjustments to the mapper, then the problem goes away.

The problem also goes away if I move the properties of the NestedTarget down to Target, i.e.

@Value
@Builder
public class Target {
    Long testing;
    Long testingToo;
}}

Please let me know if you need more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions