I have a problem with Getting started example from ModelMapper with Java8. They show that using their library you can define mappigs like
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(mapper -> {
mapper.map(src -> src.getBillingAddress().getStreet(), Destination::setBillingStreet);
mapper.map(src -> src.getBillingAddress().getCity(), Destination::setBillingCity);
});
what obviously doesn't work and what's more cannot work since ModelMapper
is not generic (so you cannot infer src
and dst
types)
public class ModelMapper {
...
}
and what's more map()
method does not accept functional interface but PropertyMap
object
public abstract class PropertyMap<S, D> {
...
}
I've checked ModelMapper Github page to see examples but it seems that they are using Java6/7 approach everywhere... :) Why then there is such example for Java8 in Getting started if it is not working and has no chance to work?
Have you ever investigated this? What am I doing wrong?
I use ModelMapper 2.3.0
EDIT
it should be
ModelMapper modelMapper = new ModelMapper();
modelMapper.createTypeMap(Order.class, OrderDTO.class)
.addMappings(mapper -> {
mapper.map(src -> src.getBillingAddress().getStreet(), OrderDTO::setBillingStreet);
mapper.map(src -> src.getBillingAddress().getCity(), OrderDTO::setBillingCity);
});
It seems that in official tutorial they named modelMapper
TypeMap instance not ModelMapper :)