Mapping Dozer vs MapStruct

In multi-tier applications there is often a need for mapping between two data models. In this article you can read about comparing two mapping libraries:

The most common use case is coping data from entity objects to DTO objects usually used in service REST/SOAP.

Mapping rules are defined in XML files, which are then loaded during application runtime.
Dozer is using reflection mechanism for mapping.
Mapping rules are defined in Java files, mostly in annotations. Based on this rules MapStruct generates Java classes, which are then used for mapping.
SpeedDozer uses reflection mechanism for mapping, which means it is slower than MapStruct.
In example (link) it is mapped 1 000 000 objects.
On my notebook it takes about 16 seconds.
MapStruct invoke methods of classes, which were generated before compilation.
Thanks to that it works faster than Dozer.
In example (link) it is mapped 1 000 000 objects.
On my notebook it takes about 3 seconds.
MapStruct is about 500% faster than Dozer.
When you make a mistake in XML that contains mapping rules you will know about it only during invoking mapping (runtime error).When you make a mistake in property name, you will know about it during compilation. Thanks that application will be more reliable.
Immutable objectsDozer can access private properties (by reflection). It makes possible to map immutable objects which haven’t setters. It requires that immutable object has a constructor without parameters and in mapping files you should add attribute is-accessible="true" to destination fields.Unfortunately MapStruct hasn’t ability to map immutable objects.
There is an open issue about that.
DebuggingMapping rules are defined mostly in XML files. During application runtime that files are loaded. Thus debugging mapping process is difficult – you have to set breakpoints in Dozer classes.You can set breakpoint in classes, which was generated during compilation. Thanks that you can easily determine which classes are used for mapping and debug them.
(as at the date 23.03.2016)
Creation date: 04.06.2005
Stackoverflow: 1610 posts
Last release date: 22.04.2014
Creation date: 22.05.2012
Stackoverflow: 108 posts
Last release date: 16.03.2016
Additional advantages
  1. More default mapping for example: Joda-Time, JAXBElement
  2. Mapping code only in Java files – faster determination, which code is responsible for data mapping.
  3. Event handling (@BeforeMapping, @AfterMapping)
  4. Built-in support for decorators

I've prepared a small application, which does the same mapping using Dozer and MapStruct libraries. You can easily notice the difference in speed.