-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Milestone
Description
Erroneous Unmapped target property compilation error when private collection field has a get method but no set method.
Versions: Java 11, Mapstruct 1.5.2-Final.
Given the following classes:
public class Source {
private String sourceField;
public Source() {
// no-op
}
public String getSourceField() {
return sourceField;
}
public void setSourceField(String sourceField) {
this.sourceField = sourceField;
}
}
public class Target {
private final Map<String, String> attributes = new HashMap<>();
private String targetField;
public Target() {
// no-op
}
public Map<String, String> getAttributes() {
return attributes;
}
public String getTargetField() {
return targetField;
}
public void setTargetField(String targetField) {
this.targetField = targetField;
}
}
@Mapper
public interface S2TMapper {
@Mapping(target = "targetField", source = "sourceField")
Target map(Source source);
}When the compiler is run we get the following compilation error.
If the getAttributes method is ommitted, everything compiles fine, so it seems Mapstruct mistakenly believes the field should be writable on the basis that it has an accessor.
NOTE: I haven't tested this with other collection type classes.
Reporoducible project here
