-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Hi team,
We have this particular mapper with MapStruct 1.4.1:
// We're using Immutables
@Value.Immutable
public interface DestType {
String getId();
Status getStatus();
FooEnumType getFoo();
List<ItemType> getItems();
}
@Mapping(target = "id", source = "source1.id")
@Mapping(target = "status", source = "source1.activeStatus")
@Mapping(
target = "items",
expression = "java(mapToItems(source2, sourceMap))"
)
DestType map(SourceType source1, String source2, Map<String, BarEnumType> sourceMap);
List<ItemType> mapToItems(String src1, Map<String, BarEnumType> sourceMap) { ... }Apparently, MapStruct 1.5.0.Beta2 doesn't know sourceMap is used in the expression mapping, and will try to also map it to other unmapped field(s) in DestType, specifically the FooEnumType getFoo() field. Then it produces errors like this:
error: The following constants from the property "BarEnumType foo" enum have no corresponding constant in the "FooEnumType foo" enum and must be be mapped via adding additional mappings: BAR_ENUM_VAL1, BAR_ENUM_VAL2, (other BarEnumType values)
I've searched in the issues and the doc, but couldn't find directives to disable the auto Map to Bean mapping in this case. I know it probably can be worked around by specifically list all unmapped fields in DestType, so that MapStruct knows the sourceMap won't need to be processed, but could there be a simpler way to do this? Also our real target type has many other unrelated fields, which we don't really intend to list all for working around the Map issue.
p.s: @AfterMapping also won't work as DestType is an Immutables generated type, thus can't be mutated with AfterMapping.
Again thanks for your great work!