-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Use case
We are using MapStruct to map between our applications model and the model of an external library we have no control over. For convenience, the authors of the external library have created additional withers for each property, something like this:
public class TargetType {
public void setX(String x) {
this.x = x;
}
public TargetType withX(String x) {
setX(x);
return this;
}
}The problem is, that MapStruct automatically accepts fluent setters as target properties and with a strict target policy, we have to additionally exclude every single wither, which can (depending on the model) immensely bloat up the list of ignored properties:
@Mapper
public interface MyMapper {
@Mapping(target = "withX", ignore = true)
@Mapping(target = "withY", ignore = true)
@Mapping(target = "withZ", ignore = true)
TargetType toTargetType(SourceType source);
}Generated Code
I don't think any additional code generation is necessary, but more like an option, that could be set for a mapper:
@Mapper(namingPolicy = @NamingPolicy(allowFluentSetters = false, allowSetters = true))
public interface MyMapper {
TargetType toTargetType(SourceType source);
}The default AccessorNamingStrategy should then respect these options.
Possible workarounds
Custom AccessorNamingStrategy which is a bit cumbersome as we can't just create a class in the project itself. It has to be in another project, which then gets put on the annotation processors classpath.
MapStruct Version
1.5.3