I have a DTO with a lot of String fields (some are of other types).
When mapping objects into objects of another similar class, I need to apply a transformation to all fields of type String, in this case - trim().
So, I have:
class MyDTO {
String name;
String type;
String company;
String status;
String whatever;
... (there are about 80 String fields)
int someNumber;
double otherNumber;
}
class DestinationDTO { // has just some fields of MyDTO
String name;
String type;
String company;
String whatever;
int somenumber;
}
What I've tried:
Converter<String, String> myConverter = c -> c.getSource().trim();
ModelMapper mm = new ModelMapper();
...
mm.typeMap(MyDTO.class, DestinationDTO.class)
.addMappings(c -> c
.using(myConverter)
.map(MyDTO::getName, DestinationDTO::getName)
) // this applies to just one field, I need all String fields
Is there a way to specify all String fields of a class at once, instead of having to list them?
Tried searching the modelmapper.org docs, but all I see is configuring fields one by one.
Any ideas?