-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Ambiguous Mapping Migration Issues from CR1 to CR2/Final #1003
Description
MapStruct appears to have lost the ability to automatically resolve the correct setter function when there are multiple of the same name. This is happening for me when mapping to Protobuf generated classes with Builder setter functions. These have the unfortunate habit of violating POJO conventions, and cannot be annotated because they are generated.
In this example, we map a BillingAddress POJO to a generated Protobuf Address.Builder class.
In the Protobuf file (simplified), we have a conflict on setAddress:
void setAddress(Address value){
this.address = value;
}
void setAddress(AddressBuilder builderForValue){
this.address = builderForValue.build();
}
Our code (simplified):
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = "spring",
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
uses = {BuilderFactory.class, MyMappingFunctions.class})
public interface MyMapping {
@Mappings({
... field mappings ...
})
@Named("mapAddress")
Address.Builder mapAddress(BillingAddress billingAddress);
@Mappings({
@Mapping(source = "input.billingAddress", target = "address",
qualifiedByName = "mapAddress"),
})
@Named("mapCustomer")
public PersonalDetails.Builder mapCustomer(
Input input);
}
I was able to workaround this by overriding isSetterMethod in the SPI and explicitly returning false for the function that I did not want, and true for the builder function. It is unclear why this cannot be resolved automatically. mapAddress operates exclusively on the Address.Builder class.