0

Using MapStruct, we want to use ReportingPolicy.ERROR, and have code like the following:

@Mapping(source = "nestedSource.doublyNestedSourceField", target = "nestedTarget.doublyNestedTargetField")
Target mapSourceToTarget(Source source);

Where nestedSource is not the same type as nestedTarget, and both doublyNested*Field types are String.

There is no mapper declared for NestedSource -> NestedTarget. The String properties declared in the Mapping above are the only ones in those types.

The above causes an unmapped source error:

Unmapped source property: "doublyNestedSourceField".

That seems more-or-less reasonable, as we didn't declare a mapper for NestedSource -> NestedTarget.

However, here's the issue: If we change the ReportingPolicy for unmapped sources to warn/ignore, MapStruct figures out how to correctly map the doublyNestedSourceField in the mapper implementation, even though it claims there is no source mapping present. Just wondering what is going on here, and whether I'm missing something.

----Into the weeds a bit more (in the MapStruct code itself)----

I could be doing something wrong, but I did notice that in BeanMethodMapping.java MapStruct attempts to remove "nestedSource.doubleNestedSourceField" from unprocessedSourceProperties, even though the key for the appropriate property is just "nestedSource" in unprocessedSourceProperties. Thus "nestedSource" is left as an unprocessed source property and an error is thrown.

Zobia Kanwal
  • 4,085
  • 4
  • 15
  • 38
jengelhart
  • 97
  • 3
  • 9

0 Answers0