how does Model Mapper work behind the scenes?

2010 views
Skip to first unread message

syed rizwan

unread,
Apr 17, 2013, 2:41:29 AM4/17/13
to model...@googlegroups.com
How does Model Mapper performs mapping when compared to other mapping frameworks? 
The below link shows a comparison of the performance of ModelMapper to that of Dozer.


How does model mapper achieves this? Can you given highlights on internal/implementation details?

Jonathan Halterman

unread,
Apr 17, 2013, 11:41:49 AM4/17/13
to model...@googlegroups.com
Hi Syed,

I can't speak to how ModelMapper works as compared to Dozer, but I can certainly describe ModelMapper. 

First, have a look at the How it Works page in the docs, which describes how ModelMapper's implicit matching process works. For each source and destination type, ModelMapper creates a TypeMap which contains mappings that are either created implicitly by ModelMapper (as determined by the property matching process) or explicitly by user supplied PropertyMaps. Mappings describe exactly which path through the source object graph matches which path in the destination object graph (ex: Company.employee.address.street -> CompanyDTO.employeeStreetAddress), as well as other information. 

When ModelMapper.map is called, the TypeMap for the source and destination types is looked up and values are mapped accordingly. If no TypeMap exists for the source and destination types, one is created on the first map call and is reused thereafter. Mapping is an efficient process since all of the information needed to copy property values from an object of the source type to an object of the destination type is already captured in the TypeMap.

Hope that helps,
Jonathan

syed rizwan

unread,
Apr 22, 2013, 2:50:08 AM4/22/13
to model...@googlegroups.com
Hi Jonathan,

These insights are useful. I understand that what involved basically is caching with the help of maps.

Thanks

--
Syed Rizwan

VLADIMIR KRASILSCHIK

unread,
Aug 12, 2013, 4:08:19 PM8/12/13
to model...@googlegroups.com
Hi, Jonatan!

Could you please be more specific about underlying mapping method: is it reflection-based?

Best regards,

Vladimir Krasilschik

Jonathan Halterman

unread,
Aug 12, 2013, 4:22:36 PM8/12/13
to model...@googlegroups.com
Hi Vladimir,

Yes, it uses reflection.

Cheers,
Jonathan
Reply all
Reply to author
Forward
0 new messages