Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmapped source properties error when source is mapped to a nested field of the target object #2781

Closed
JCCorreale opened this issue Mar 9, 2022 · 2 comments · Fixed by #2813
Labels
Milestone

Comments

@JCCorreale
Copy link

JCCorreale commented Mar 9, 2022

An example to reproduce this issue can be found in this repository

The issue is easily reproducible with this simple mapping:

@Mapping(target = "nested", source = "mySource")
MyTarget map(MySource mySource);

Where MyTarget.nested is of type MySource

When unmappedSourcePolicy is set to ReportingPolicy.ERROR, the report produces Unmapped source properties error (or warning in the case of ReportingPolicy.WARN)

The mapping code is generated correctly. For ReportingPolicy.ERROR, the following workaround is necessary in order to get a successful build:

@BeanMapping(ignoreUnmappedSourceProperties = { "field1", "field2" })

Where "field1", "field2" are the fields of MySource

MapStruct version is 1.4.2.Final

Best regards
JC

@Tockra
Copy link

Tockra commented Mar 15, 2023

It's still an issue:

Classes:

@JsonInclude(JsonInclude.Include.NON_NULL)
public record TargetClass(
    String id,
    String name,
    NestedClass nested) {
}
public record NestedClass(SomeEnum enum) {

}

MapStruct:

//...
    @Mapping(target = "nested.enum", source = "nameOfEnumAttrInSourceClass")
    public abstract TargetClass sourceClassToTargetClass(SourceClass entity);
//....

@filiphr filiphr added bug and removed enhancement labels Apr 16, 2023
@filiphr
Copy link
Member

filiphr commented Apr 16, 2023

@Tockra the issue is still open, so yes the original problem is still a problem. However, from your example I can't really understand how it is linked to the original problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants