BeanUtils.copyProperties() vs DozerBeanMapper.map()
Solution 1
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() {
map().setBillingStreet(source.getBillingStreetAddress());
skip().setBillingCity(null);
}
});
Check out the project homepage for more info:
Solution 2
We considered mapstruct for our usecase. See a sample below:
@Mapper
public interface MyMapper {
MyMapper INSTANCE = Mappers.getMapper(MyMapper.class);
To to(From from);
}
Here is a performance comparison of MapStruct against Selma, Orika, ModelMapper, Dozer and manual mapping:
![Pankaj Kumar](https://i.stack.imgur.com/04gz5.png?s=256&g=1)
Pankaj Kumar
A 'Mobile Device Management', 'AOSP' developer who also knows about Flutter, Swift and had love affaire with 'C'. I used to spend my free time on Stackoverflow and loves to answer (and ask Questions too :) ). Few Android-specific badges: Android Silver Badge - was 214th in the world - awarded on 21st Jun 2013 Android Gold Badge - was 81st in the world - awarded on 4th Apr 2014 My codes are running for 15+ Android applications, few of them are : Samsung Knox HP Touchpoint Manager 1Mobility Discover Mobile Kloojj HSBC - FX
Updated on June 04, 2022Comments
-
Pankaj Kumar about 2 years
I am using
BeanUtils.copyProperties()
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 usedDozerBeanMapper.map()
, 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.
-
Marcin Erbel over 5 yearsDo you have anywhere comaprison between MapStruct and BeanUtils.copyProperties()?