I need a mapping to achieve this:
@Mapping(source = "a", target = "result.transactions[0].a"),
@Mapping(source = "b", target = "result.transactions[0].b"),
@Mapping(source = "c", target = "result.transactions[0].c"),
...
Response dataToResponse(DataModel model);
But this syntax does not work (btw: This works with Spring Bean wrapper). A solution like this is just a half-cooked solution:
@AsList
public <T> List<T> asList( T in ) {
List<T> result = new ArrayList<T>();
if ( in!=null ) {
result.add(in);
}
return result;
}
This only works for exactly one attribute since it always creates a new list for each attribute. I don't need to map each attribute to the first element of a new list. The list must be reused but I don't know how this works. What is the proper way to achieve that? I thought about something like this:
@Mapping(source = "a", target = "transaction.a"),
@Mapping(source = "b", target = "transaction.b"),
@Mapping(source = "c", target = "transaction.c"),
...
Transaction dataToTransaction(DataModel model);
and then...
@Mapping([use Transaction from b4], target = "result");
But how can I pass the already mapped fields from above? (I'm using the latest final release 1.1.0.Final)