Trying to use value objects in my business model, I'm facing issues with the following code :
@Mapper
public abstract class TestMapstruct {
public ValueObjectA mapA(String value){
return new ValueObjectA(value);
}
public abstract BusinessObject map(DTO dto);
@Value
public static class ValueObjectA {
private String a;
}
@Value
public static class ValueObjectB {
private String b;
}
@Data
public static class BusinessObject {
private ValueObjectA a;
private ValueObjectB b;
}
@Data
public static class DTO {
private String a;
private String b;
}
}
Missing mapping (String -> ValueObjectB) would lead to the following compilation error message :
Can't map property "java.lang.String b" to "test.ValueObjectB b". Consider to declare/implement a mapping method: "test.ValueObjectB map(java.lang.String value)".
I totally understand this, but I would rather not to declare a method for each of my ValueObjects (could have dozens in a project).
Is there a generic way to declare (String -> ValueObject) mapping method ?