Hi,
this is not critial issue, but after switch from 1.2.0.Final to 1.3.0.Final nearly each mapping got warnings for our own clone-methods: Unmapped target property: "clone".
Our framework generate data beans with following "build-in" methods:
public Dto clone() {
Dto clone = new Dto();
return this.clone(clone);
}
public Dto clone(Dto clone) {
if (this.getAttr() == null) {
clone.setAttr(null);
} else {
clone.setAttr(this.getA());
}
return clone;
}
MapStruct 1.3.0.Final throw warnings "Unmapped target property" for second method clone with parameter. Possible because this method recognised as fluent setter?
I added @Mapping(target = "clone", ignore = true) as workaround, but this dosn't work for collections of embeded dtos because default mappings: (Unmapped target property: "clone". Mapping from Collection element "Bean bean" to "Dto dto").
Those methods are now considered as fluent setters.
Will the proposed solution in https://github.com/mapstruct/mapstruct/issues/1726#issuecomment-465285942 be valid option for you? The proposal is to have a compiler option that would disable fluent setters.
That aside, mind if I ask you why you need the clone when you use MapStruct 馃槃?
We have a similar issue. Here's a code of generated DTO. It's ugly, and, unfortunately, we do not have control over a generation process:
public class GeneratedEntity {
private String name;
public String getName() {
return name;
}
// setter for a **name** property
public void setName(String name) {
this.name = name;
}
// fluent setter for a **name** property
public GeneratedEntity withName(String name){
setName(name);
return this;
}
}
Two methods here sets the same property, but have different names (setName and withName). The latter is treated as fluent setter so now we get an error that a withName property is not mapped. In those generated DTOs there is a method for each property, so going with ignoring all such properties with a dedicated @Mapping annotation is a bit cumbersome.
As for compiler flag for ignoring fluent setters - that sounds great. It will solve our problem.
The other idea is to add a ignoreFluentSetters parameter to @Mapper annotation. Not sure that is possible though.
Anyway - thank you for a great tool!
IMHO the better choice is, when the fluent setters are disabled by default and can be activated by compiler option. ;-)
It is a bit strange that in the class "Dto" methods with parameter type and return type Dto considered as fluent setters. This methods don't mapped any attribute in the Dto class.