Pankaj Kumar Pankaj Kumar -4 years ago 401
Java Question

BeanUtils.copyProperties() vs

I am using

for bean to dto mapping when I need to map all fields and field names are same. But I need not all field of source bean to map in destination dto, I used
, because I haven't idea about to use BeanUtils in this situation.

So I think both methods having their own functionality, and there is no any similarity between both. Am I right? Please guide me.

Answer Source

You might check out ModelMapper. It will intelligently map properties (fields/methods) even if the names are not exactly the same. Defining specific properties to be mapped or skipped is simple and uses real code instead of XML:

ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
  protected void configure() {

Check out the project homepage for more info:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download