I'm using ModelMapper with Spring. In my controller class I'm autowiring the ModelMapper bean:
@Autowired
private ModelMapper mapper;
I want to do an explicit mapping between my model class and my DTO in my controller methods, something like:
modelMapper.addMappings(mapper -> {
mapper.map(src -> src.getBillingAddress().getStreet(),
Destination::setBillingStreet);
mapper.map(src -> src.getBillingAddress().getCity(),
Destination::setBillingCity);
});
And then use the mapper to map the classes.
My question is, is it right to add explicit mappings in every controller method call? Will object modelMapper start to grow in memory size?
Other solution is to add the mapping only one time when ModelMapper bean is created, but I don't think that putting mapping logic in a bean configuration is a good decision.