I have custom mapping function that maps int to String, but I only want it to be applied in one special case. However, it is applied to all source-fields of type int, not just the one annotated with java(...).
Source class:
class Source {
private int a;
private int b;
// getters etc...
}
Target class:
class Target {
private String a;
private String b;
// getters etc...
}
Mapper:
@Mapping(source="a", target="a") // should not be necessary, but to make it more explicit
@Mapping(target="b", expression = "java(modify(b))")
public abstract Target sourceToTarget(Source source);
String modify(int value) {
return "prefix_" + value;
}
What I want to achieve:
target.setA(String.valueOf(a));
target.setB(modify(b));
However, the generated code does this:
target.setA(modify(a));
target.setB(modify(b));
When removing the expression and modify, MapStruct uses String.valueOf for both values.
I tried it with both MapStruct 1.4.2.FINAL as well as 1.5.2.FINAL. Both classes make use of Lombok, however, this hasn't been a problem in the past.
Is this behavior expected? If yes, how else can I make it work?