Skip to main content

Dozer Bean Mapping in Java: Practical Guide, Pitfalls, a Migration Path to MapStruct and a Real Benchmark

Dozer 7.0.0 examples from basic mapping to Spring, the failures it hides (silent nulls, one-way converters, records), a measured JMH benchmark against MapStruct, and a step-by-step migration with a parity test.

In modern Java applications — particularly those built on Spring Boot or Jakarta EE — moving data between object models is a daily reality. You have DTOs (Data Transfer Objects) arriving from REST APIs and you need to convert them into Domain Entities for persistence, or vice versa. Writing manual getter-setter copy code for every field is tedious, error-prone, and buries your business logic under a mountain of boilerplate that grows with every new field added to your model.

Enter Dozer — a robust, open-source Java Bean mapper that recursively copies data from one object to another using reflection. Dozer has been a production staple for over a decade. While compile-time alternatives like MapStruct have gained popularity for performance-critical applications, Dozer remains a compelling choice for its runtime flexibility, zero build-plugin setup, and its ability to handle complex mapping scenarios without annotation proliferation on your model classes.

In this guide, we will cover practical Dozer usage from basic field mapping through nested objects, custom converters, and Spring integration. Then we will do what the first version of this post only talked about: run Dozer and MapStruct side by side, watch where Dozer fails quietly, measure both with JMH, and walk through a migration from one to the other. If you are new to bean mappers, read straight through; each section needs only the one before it. The deeper material sits in the collapsible panels, so you can skip it on a first read.

Versions tested. JDK 25.0.5.1 (Temurin, LTS); Dozer dozer-core 7.0.0 (Maven Central, 2024-03-05, the newest release); MapStruct 1.6.3 (newest GA, 2024-11-09; 1.7.0.Beta2 is the latest artifact on Central but it is a beta); JMH 1.37; JUnit 5.11.0. Every output block on this page is quoted from a file in the companion module, regenerated by ./scripts/run-all.sh.

What this rewrite corrects. The earlier version of this post called 6.5.0 the final Dozer release (7.0.0 shipped in March 2024), said Java records work as a Dozer source (they copy nothing, silently), showed a .mapNull(false) call that does not exist, and quoted benchmark numbers “widely reported in the community” instead of measuring any. The measured numbers below are much further apart than the old table suggested. Details are in the relevant sections.

Why use a bean mapper at all?

A typical layered application maintains at least three object representations of the same data: an API DTO (shaped for the consumer), a domain entity (shaped for business logic), and a persistence entity (shaped for the database). Manually copying between these introduces several risks: missed fields when a model is updated, inconsistent null handling, and tight coupling between layers. A bean mapper like Dozer encapsulates all field mapping rules in one place, so adding a new field to the DTO and the entity automatically propagates the mapping without touching service code.

REST clientJSONUserDTOemailMapperDozer or MapStructUserEntityemailAddressDatabasecolumn email_addressOnly the mapper knows that email and emailAddress are the same field.Move that knowledge into service code and every new field is a chance to forget one copy line.

The picture is the whole job: a request arrives as a UserDTO, leaves as a UserEntity, and the mapper is the single place that knows how the two shapes relate. Everything below uses exactly this pair of classes, so you can follow the same objects through Dozer, then MapStruct. The classes are plain JavaBeans (UserDTO, UserEntity); the one wrinkle is that the DTO says email and the entity says emailAddress.

Dozer needs one dependency and one Mapper

Add dozer-core to your pom.xml. No annotation processors or build plugins are required.

<dependency>
  <groupId>com.github.dozermapper</groupId>
  <artifactId>dozer-core</artifactId>
  <version>${dozer.version}</version>
</dependency>

That is the dependency block from the module’s pom.xml, where the property dozer.version is 7.0.0. The first version of this post pinned 6.5.0; 7.0.0 is the current release and, according to its GitHub release notes, drops Java 8, OSGi and Proto3 support and adds Jakarta support. Everything on this page ran against 7.0.0 on JDK 25 with plain POJOs. I did not test Spring Boot here.

Instantiate the Mapper once — in a Spring application, define it as a singleton @Bean. Creating a new mapper per request is a serious performance antipattern because the mapper must parse all mapping metadata on each construction.

@Configuration
public class DozerSpringConfig {

    @Bean
    public Mapper dozerMapper() {
        return DozerBeanMapperBuilder.buildDefault();
    }
}

This is <a href="https://ankurm.com/wp-content/uploads/2026/12/DozerSpringConfig.java" download>DozerSpringConfig.java</a>, a Spring snippet kept out of the repository (the module has no Spring dependency) and available as a download. I compiled it against Spring Framework 7.1.0 but did not run it. How bad is the per-call antipattern? The benchmark below builds a new mapper on every call: 9.2 ops/ms against 221 for a reused mapper, about 24 times slower, and the benchmark does not even count the garbage.

Same-named fields map themselves; a mismatch takes one line

When field names match between source and destination, Dozer maps them automatically via convention. For mismatched names, use the fluent BeanMappingBuilder API. Here are the two classes’ fields side by side — note email against emailAddress:

private long id;
private String username;
private String email;
private ProfileDTO profile;
private List<String> tags = new ArrayList<>();

private long id;
private String username;
private String emailAddress;
private ProfileEntity profile;
private List<TagEntity> tags = new ArrayList<>();

Fields from UserDTO.java (top) and UserEntity.java (bottom). The mapping that connects them is DozerSetup.java. The first .fields line renames email; the second is the tag converter, which the collections section explains:

public static Mapper standard() {
    BeanMappingBuilder builder = new BeanMappingBuilder() {
        @Override
        protected void configure() {
            mapping(UserDTO.class, UserEntity.class)
                    .fields("email", "emailAddress")
                    .fields("tags", "tags", FieldsMappingOptions.customConverter(TagListConverter.class));
        }
    };
    return DozerBeanMapperBuilder.create().withMappingBuilder(builder).build();
}

Using it is one map call, and the output is quoted from output/01-dozer-tour.txt:

UserDTO dto = Samples.flat();
UserEntity entity = mapper.map(dto, UserEntity.class);
System.out.println("ID: " + entity.getId());
System.out.println("User: " + entity.getUsername());
System.out.println("Email: " + entity.getEmailAddress());
== 1. Basic mapping: id and username by name, email -> emailAddress by configuration
ID: 1
User: ankurm
Email: [email protected]

The id and username fields are mapped automatically. Only the mismatched email → emailAddress pair requires explicit configuration. The input object comes from Samples.java; the same three inputs feed the demos, the tests and the benchmark.

Nested objects need no configuration at all

Dozer automatically traverses and maps nested object graphs — it instantiates the destination type and recursively maps all matching fields, without any additional configuration.

UserDTO nested = new UserDTO();
nested.setUsername("jdoe");
nested.setProfile(new ProfileDTO("John", "Doe"));
UserEntity nestedEntity = mapper.map(nested, UserEntity.class);
System.out.println("profile class: " + nestedEntity.getProfile().getClass().getSimpleName());
System.out.println("first name: " + nestedEntity.getProfile().getFirstName());
== 2. Nested object: no configuration at all
profile class: ProfileEntity
first name: John

Dozer instantiated a new ProfileEntity, copied firstName and lastName from the DTO profile, and assigned it to the entity — all without a single line of mapping configuration. Code: DozerTour.java.

Collections of the same type just work; different element types need a converter

Mapping a List<UserDTO> to List<UserEntity> works out of the box. For type-incompatible collections (e.g., List<String> → List<TagEntity>), implement a DozerConverter.

public class StringToTagConverter extends DozerConverter<String, TagEntity> {

    public StringToTagConverter() {
        super(String.class, TagEntity.class);
    }

    @Override
    public TagEntity convertTo(String source, TagEntity destination) {
        if (source == null) return null;
        TagEntity tag = new TagEntity();
        tag.setName(source);
        return tag;
    }

    @Override
    public String convertFrom(TagEntity source, String destination) {
        return source != null ? source.getName() : null;
    }
}

StringToTagConverter.java. Register it on the mapper and map a DTO that carries tags (code from DozerTour.java):

UserDTO tagged = new UserDTO();
tagged.setTags(java.util.Arrays.asList("Java", "Spring Boot", "Dozer"));
UserEntity taggedEntity = DozerSetup.globalConverterOnly().map(tagged, UserEntity.class);
taggedEntity.getTags().forEach(tag -> System.out.println(tag.getName()));

Output, from output/01-dozer-tour.txt:

== 3. Collection: List<String> -> List<TagEntity> through the custom converter
Java
Spring Boot
Dozer
This setup only works in one direction. Registering StringToTagConverter globally, as most tutorials (including the first version of this post) do, converts String to TagEntity correctly. Going the other way, entity to DTO, Dozer does not call convertFrom for list elements and does not complain either. The “strings” in your DTO are TagEntity.toString() output. The fix and the exact output are in the failure section below.

Dozer copies null over existing values unless you tell it not to

By default, Dozer copies null values from source to destination — if the source field is null, the destination field will be set to null as well. When you map onto an existing object, that overwrites good data. For partial updates, where the DTO carries only the fields that changed, skip nulls with TypeMappingOptions.mapNull(false), as in DozerSetup.java:

mapping(UserDTO.class, UserEntity.class, TypeMappingOptions.mapNull(false))
        .fields("email", "emailAddress")

The two behaviours side by side, from the same run:

== 5. Null handling: default Dozer copies null over an existing value
after mapping a DTO with null email and null profile: emailAddress=null, profile=null

== 6. Null handling: TypeMappingOptions.mapNull(false) keeps the existing value
after the same update: [email protected], profile=ProfileEntity[John Doe]
A correction. The first version of this post wrote the option as mapping(Src.class, Dest.class).mapNull(false). In Dozer 7.0.0 the object returned by mapping(...) has no mapNull method; the option is passed as a third argument, as above. The test chainedMapNullFromTheOldPostDoesNotExistInDozer7 in BeanMappingClaimsTest.java pins this. I checked 7.0.0 only.

One configuration maps both directions

Dozer treats a mapping as bidirectional by default, so the entity maps back to a DTO without a second definition:

== 4. Bidirectional: the same configuration maps the entity back
round trip equals original: true
UserDTO[id=1, username=ankurm, [email protected], profile=ProfileDTO[John Doe], tags=[Java, Spring Boot, Dozer, MapStruct, JMH]]

The round trip is lossless here only because the tag list has its own field-level converter (TagListConverter.java, used by DozerSetup.standard()). That detail is the next section’s first trap.

In Spring, inject the singleton Mapper into the service layer

In a Spring Boot application, inject the singleton Mapper bean into your service layer. This keeps mapping logic out of your controllers and repositories.

@Service
public class DozerUserService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private Mapper mapper;

    public UserDTO createUser(UserDTO dto) {
        UserEntity entity = mapper.map(dto, UserEntity.class);
        UserEntity saved = userRepository.save(entity);
        return mapper.map(saved, UserDTO.class); // bidirectional
    }
}

Download: <a href="https://ankurm.com/wp-content/uploads/2026/12/DozerUserService.java" download>DozerUserService.java</a>. It needs a repository type to compile, so there is a tiny stand-in, <a href="https://ankurm.com/wp-content/uploads/2026/12/UserRepository.java" download>UserRepository.java</a>; in a real application that interface extends JpaRepository. Like the configuration class above, these were compiled, not run.

Spring files, all in one place (downloads)
  • <a href="https://ankurm.com/wp-content/uploads/2026/12/DozerSpringConfig.java" download>DozerSpringConfig.java</a> — the singleton Mapper bean.
  • <a href="https://ankurm.com/wp-content/uploads/2026/12/DozerUserService.java" download>DozerUserService.java</a> — service using the Dozer mapper.
  • <a href="https://ankurm.com/wp-content/uploads/2026/12/SpringUserMapper.java" download>SpringUserMapper.java</a> — the MapStruct equivalent, @Mapper(componentModel = "spring").
  • <a href="https://ankurm.com/wp-content/uploads/2026/12/MapStructUserService.java" download>MapStructUserService.java</a> — service using the generated MapStruct mapper by constructor injection.
  • <a href="https://ankurm.com/wp-content/uploads/2026/12/UserRepository.java" download>UserRepository.java</a> — stand-in repository interface so the files compile without Spring Data.

All five compile together against the companion module, Spring Framework 7.1.0, Dozer 7.0.0 and MapStruct 1.6.3 with JDK 25. They are not part of the repository because the module deliberately has no Spring dependency, and none of them was started inside a Spring context.

Where Dozer fails quietly, and when you find out

Dozer reads and writes your classes through reflection, so the compiler knows nothing about your mapping. The practical consequence is when you learn about a mistake, and whether you learn about it at all. Every case below is one section of DozerPitfalls.java and one line of output in output/02-dozer-pitfalls.txt.

Dozerjavacchecks nothing about mappingsMapper build (application start)a typo in a field name fails hereEvery map() callreflection: look up class map, call getters/settersMapStructjavac + annotation processorunmapped target property fails hereUserMapperImpl.javagenerated, readable, debuggableEvery callplain getter/setter callsSame mapping, different moment of failure: at startup for Dozer (and only for the mistakes it can see), at build time for MapStruct.

The top row is Dozer: javac has nothing to say about a mapping, a mistake it can see surfaces when the mapper is built, and everything it cannot see surfaces never. The bottom row is MapStruct, which does its checking while compiling.

A typo in a field name fails at startup, not at compile time

Misspell a field in the mapping and Dozer throws when the mapper is built. That is better than failing on the first request, and it is why you should build the mapper eagerly at startup. It is still a runtime failure: you find out when you run the application, not when you compile it. From DozerPitfalls.java:

BeanMappingBuilder typo = new BeanMappingBuilder() {
    @Override
    protected void configure() {
        mapping(UserDTO.class, UserEntity.class).fields("emial", "emailAddress");
    }
};
== 1. A typo in a field name: when does it fail? (not at compile time)
failed while building the mapper: MappingException: No read or write method found for field (emial) in class (class com.ankurm.beanmapping.model.UserDTO)

A field nobody maps is silently left null

This is the failure that costs the most. Leave out the email line, or add a column to the entity that the DTO has no match for, and Dozer says nothing: no exception, no log line. The target field just stays at its default. The second exhibit uses UserEntityV2, which is the entity after someone added a phone column.

== 2. A field nobody maps: email -> emailAddress without the configuration line
no exception, no log line. emailAddress=null

== 3. A new column on the entity (phone): does Dozer notice?
no exception, no log line. UserEntityV2[id=1, username=ankurm, emailAddress=null, phone=null]

Both are asserted in BeanMappingClaimsTest.java (unmappedRenamedFieldIsSilentlyNullInDozer, newUnmappedTargetColumnIsSilentlyNullInDozer). MapStruct can turn the same situation into a build failure; see below.

A converter registered globally is not used for list elements in reverse

This one was found by the migration parity test, not by reading. With StringToTagConverter registered globally (the tutorial setup), List<String> to List<TagEntity> works. The reverse direction does not call convertFrom; Dozer falls back to turning each TagEntity into a string with toString(), silently.

== 5. A converter registered globally, applied to a list, entity -> DTO
DTO to entity worked: [Tag[Java], Tag[Spring Boot], Tag[Dozer], Tag[MapStruct], Tag[JMH]]
entity to DTO, no exception: tags=[Tag[Java], Tag[Spring Boot], Tag[Dozer], Tag[MapStruct], Tag[JMH]]
convertFrom() was never used: the elements are TagEntity.toString() output
with a field-level converter:    tags=[Java, Spring Boot, Dozer, MapStruct, JMH]

I tried collection hints first (hintA/hintB); they did not change the result. What did work is a converter attached to the field itself, which receives the whole list in both directions and checks the element type: TagListConverter.java, wired in by .fields("tags", "tags", FieldsMappingOptions.customConverter(TagListConverter.class)) in DozerSetup.standard().

The fingerprint of this bug. A List<String> that contains values like Tag[Java] — the toString() of the class that should have been converted. If you see your entity’s toString() format inside a DTO string field, a converter did not run.
Records: Dozer cannot map into one, and mapping from one copies nothing

Dozer relies on the JavaBeans convention: a public no-argument constructor and getX()/setX() pairs. A record has neither. The first version of this post said records could still be a source because Dozer reads via accessors. That is wrong: a record’s accessors are id() and username(), not getters, so Dozer finds nothing to read and copies nothing, and it does not tell you.

== 4. Records: as destination, then as source
record destination failed: MappingException: java.lang.NoSuchMethodException: com.ankurm.beanmapping.model.UserRecord.<init>()  [root cause NoSuchMethodException: com.ankurm.beanmapping.model.UserRecord.<init>()]
record source: no exception, but look at the result: UserDTO[id=0, username=null, email=null, profile=null, tags=[]]

MapStruct maps to and from records through the canonical constructor: RecordMapper.java, output 03. Asserted by dozerCannotMapIntoARecordButMapStructCan and dozerFromARecordCopiesNothingWithoutAnError. See also MapStruct with Spring Boot 4 and Java Records.

Lazy getters: Dozer calls them, and so does MapStruct

This is the classic Hibernate pitfall: map an entity to a DTO and Dozer calls the getter of every property the two classes share, including a lazy collection. If the session is closed, that is a LazyInitializationException; if it is open, it is an extra SELECT you did not ask for. This module has no Hibernate, so LazyUser (LazyUser.java) is a simulation: its getOrders() throws what an uninitialised collection throws and counts how often it was called. The point being demonstrated is that the getter is called, not Hibernate’s behaviour.

== 6. A lazy getter: does Dozer call it?
map() failed: MappingException: java.lang.reflect.InvocationTargetException  [root cause IllegalStateException: could not initialize proxy - no Session (simulated lazy collection)]
getOrders() was called 1 time(s)

== 7. Same kind of entity, orders excluded in the mapping
map() succeeded: LazyUserView[id=6, name=lazy2, orders=null]
getOrders() was called 0 time(s)

The fix is to exclude the property (mapping(LazyUser.class, LazyUserView.class).exclude("orders")) or to map inside an active transaction. MapStruct has exactly the same problem and the same fix (@Mapping(target = "orders", ignore = true), LazyMapper.java); the difference is that you can read the generated code and see the call. Output: 03-mapstruct-tour.txt. Asserted by dozerCallsLazyGetterUnlessExcluded and mapStructAlsoCallsLazyGetterUnlessIgnored.

Is Dozer still maintained?

Barely. Dozer 7.0.0, released on 2024-03-05, is the newest version on Maven Central, and the project’s own README says it is not currently active and will more than likely be deprecated in the future. It discourages Dozer for new projects and suggests that existing users plan a migration to another library. The first version of this post called 6.5.0 “the final stable release”; that was out of date, since 6.5.2 (2021-04-07) and 7.0.0 followed. For existing Dozer projects, 7.0.0 ran correctly for the plain-POJO cases on this page under JDK 25, so there is no emergency, but there is no future either: do not expect new features or fixes.

The same mappings in MapStruct

MapStruct is Dozer’s most prominent modern alternative. Unlike Dozer’s runtime reflection, MapStruct generates plain Java mapping code at compile time via annotation processing. Here is the whole of what DozerSetup.standard() and StringToTagConverter do, as a MapStruct interface:

@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface UserMapper {

    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    @Mapping(source = "email", target = "emailAddress")
    UserEntity toEntity(UserDTO dto);

    /**
     * One line replaces Dozer's implicit bidirectionality. The name is required once an update method
     * exists: without it MapStruct reports "Several matching inverse methods exist: toEntity(), update()".
     */
    @InheritInverseConfiguration(name = "toEntity")
    UserDTO toDto(UserEntity entity);

    ProfileEntity toEntity(ProfileDTO profile);

    ProfileDTO toDto(ProfileEntity profile);

    /** Dozer needed a DozerConverter class for this; MapStruct picks up any method with the right types. */
    default TagEntity toTag(String name) {
        return name == null ? null : new TagEntity(name);
    }

    default String fromTag(TagEntity tag) {
        return tag == null ? null : tag.getName();
    }

    /** Partial update: a null in the DTO leaves the entity's value alone (Dozer: mapNull(false)). */
    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    @Mapping(source = "email", target = "emailAddress")
    void update(@MappingTarget UserEntity target, UserDTO source);
}

UserMapper.java. Three things to notice. The email rename is an annotation. The converter class is two small default methods, and MapStruct finds them by type, including for list elements. And unmappedTargetPolicy = ReportingPolicy.ERROR is the line that makes the silent-null failures above impossible. The output of MapStructTour.java for the same inputs:

== 1. Basic + nested + collection in one mapper
UserEntity[id=1, username=ankurm, [email protected], profile=ProfileEntity[John Doe], tags=[Tag[Java], Tag[Spring Boot], Tag[Dozer], Tag[MapStruct], Tag[JMH]]]

== 2. Bidirectional through @InheritInverseConfiguration
round trip equals original: true

The parity of the two libraries on these inputs is not just visual: the test in the migration section asserts it for every field.

A new unmapped column breaks the build instead of production

Remember UserEntityV2, the entity that gained a phone column which Dozer silently left null? Here is the same situation as a MapStruct mapper (BrokenUserMapper.java, kept outside the Maven build and compiled by compile-broken.sh). This is the compiler’s own message, quoted from output/05-broken-compile.txt:

$ javac -processorpath target/processor/mapstruct-processor-*.jar -cp target/classes:target/lib/mapstruct-*.jar src/broken/java/BrokenUserMapper.java
src/broken/java/BrokenUserMapper.java:14: error: Unmapped target property: "phone".
    UserEntityV2 toEntity(UserDTO dto);
                 ^
1 error
javac exit code: 1
Read the generated code: what MapStruct actually runs

The annotation processor writes UserMapperImpl.java into target/generated-sources. It is the file you would have written by hand, which is why the benchmark below puts MapStruct next to hand-written code. Quoted from output/04-UserMapperImpl.java.txt (the date line in the @Generated annotation changes on every build):

package com.ankurm.beanmapping.mapstruct;

import com.ankurm.beanmapping.model.ProfileDTO;
import com.ankurm.beanmapping.model.ProfileEntity;
import com.ankurm.beanmapping.model.TagEntity;
import com.ankurm.beanmapping.model.UserDTO;
import com.ankurm.beanmapping.model.UserEntity;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2026-12-01T08:07:17+0530",
    comments = "version: 1.6.3, compiler: javac, environment: Java 25.0.5.1 (Eclipse Adoptium)"
)
public class UserMapperImpl implements UserMapper {

    @Override
    public UserEntity toEntity(UserDTO dto) {
        if ( dto == null ) {
            return null;
        }

        UserEntity userEntity = new UserEntity();

        userEntity.setEmailAddress( dto.getEmail() );
        userEntity.setId( dto.getId() );
        userEntity.setUsername( dto.getUsername() );
        userEntity.setProfile( toEntity( dto.getProfile() ) );
        userEntity.setTags( stringListToTagEntityList( dto.getTags() ) );

        return userEntity;
    }

    @Override
    public UserDTO toDto(UserEntity entity) {
        if ( entity == null ) {
            return null;
        }

        UserDTO userDTO = new UserDTO();

        userDTO.setEmail( entity.getEmailAddress() );
        userDTO.setId( entity.getId() );
        userDTO.setUsername( entity.getUsername() );
        userDTO.setProfile( toDto( entity.getProfile() ) );
        userDTO.setTags( tagEntityListToStringList( entity.getTags() ) );

        return userDTO;
    }

    @Override
    public ProfileEntity toEntity(ProfileDTO profile) {
        if ( profile == null ) {
            return null;
        }

        ProfileEntity profileEntity = new ProfileEntity();

        profileEntity.setFirstName( profile.getFirstName() );
        profileEntity.setLastName( profile.getLastName() );

        return profileEntity;
    }

    @Override
    public ProfileDTO toDto(ProfileEntity profile) {
        if ( profile == null ) {
            return null;
        }

        ProfileDTO profileDTO = new ProfileDTO();

        profileDTO.setFirstName( profile.getFirstName() );
        profileDTO.setLastName( profile.getLastName() );

        return profileDTO;
    }

    @Override
    public void update(UserEntity target, UserDTO source) {
        if ( source == null ) {
            return;
        }

        if ( source.getEmail() != null ) {
            target.setEmailAddress( source.getEmail() );
        }
        target.setId( source.getId() );
        if ( source.getUsername() != null ) {
            target.setUsername( source.getUsername() );
        }
        if ( source.getProfile() != null ) {
            target.setProfile( toEntity( source.getProfile() ) );
        }
        if ( target.getTags() != null ) {
            List<TagEntity> list = stringListToTagEntityList( source.getTags() );
            if ( list != null ) {
                target.getTags().clear();
                target.getTags().addAll( list );
            }
        }
        else {
            List<TagEntity> list = stringListToTagEntityList( source.getTags() );
            if ( list != null ) {
                target.setTags( list );
            }
        }
    }

    protected List<TagEntity> stringListToTagEntityList(List<String> list) {
        if ( list == null ) {
            return null;
        }

        List<TagEntity> list1 = new ArrayList<TagEntity>( list.size() );
        for ( String string : list ) {
            list1.add( toTag( string ) );
        }

        return list1;
    }

    protected List<String> tagEntityListToStringList(List<TagEntity> list) {
        if ( list == null ) {
            return null;
        }

        List<String> list1 = new ArrayList<String>( list.size() );
        for ( TagEntity tagEntity : list ) {
            list1.add( fromTag( tagEntity ) );
        }

        return list1;
    }
}

Every call is a straight line of getters and setters. There is no mapper object to configure, no class-map cache, and the JIT can inline all of it. That is the entire reason for the performance gap measured next.

A trap I hit while writing the MapStruct version: ambiguous inverse

My first UserMapper used a bare @InheritInverseConfiguration on toDto to get Dozer-style bidirectionality. It compiled until I added the partial-update method with @MappingTarget, at which point two methods looked like the inverse of each other. The compiler’s message, from output/05-broken-compile.txt (BrokenInverseMapper.java):

$ javac -processorpath target/processor/mapstruct-processor-*.jar -cp target/classes:target/lib/mapstruct-*.jar src/broken/java/BrokenInverseMapper.java
src/broken/java/BrokenInverseMapper.java:21: error: Several matching inverse methods exist: toEntity(), update(). Specify a name explicitly.
    @InheritInverseConfiguration
    ^
src/broken/java/BrokenInverseMapper.java:22: warning: Unmapped target property: "email".
    UserDTO toDto(UserEntity entity);
            ^
1 error
1 warning
javac exit code: 1

The fix is to name the method: @InheritInverseConfiguration(name = "toEntity"), which is what UserMapper does.

Benchmark: measured, and further apart than the old table said

The first version of this post gave a table of numbers “widely reported in the community” (about 800 ops/ms for Dozer, about 7% of hand-written code). Nobody measured anything for that table, including me. So here is a real one, from MappingBenchmark.java: hand-written code, MapStruct and Dozer, each mapping a flat DTO (id, username, email) and a nested one (plus a profile and five tags) into the entity, plus the per-call-mapper antipattern. JMH 1.37, 3 forks, 3 warmup and 8 measured iterations of one second each.

1101001,00010,000100,000manual flat36,659 ops/msMapStruct flat31,096 ops/msDozer flat221 ops/msmanual nested12,398 ops/msMapStruct nested16,205 ops/msDozer nested160 ops/msDozer, new mapper per call9 ops/msThroughput in operations per millisecond, logarithmic axis: each gridline is ten times the one before it.Longer is faster. Bars are scores; the table below carries the error bars.

The bars say what the numbers below say: MapStruct sits within the same band as hand-written code, and Dozer is two orders of magnitude lower. On a logarithmic axis the Dozer bars are visibly a different kind of thing, and the red bar is what happens when the mapper is rebuilt on every call.

Benchmark (ops/ms)Score ± error (99.9%)% of hand-written
manual, flat36,659 ± 11,550100%
MapStruct, flat31,096 ± 6,51785%
Dozer 7.0.0, flat221 ± 830.60%
manual, nested12,398 ± 3,307100%
MapStruct, nested16,205 ± 2,773131%
Dozer 7.0.0, nested160 ± 421.29%
Dozer 7.0.0, new mapper per call, flat9.2 ± 4.10.03%

Quoted from output/07-benchmark.json and output/07-benchmark.txt. Against the old claim: Dozer measured 0.60% (flat) and 1.29% (nested) of hand-written code, not 7%; MapStruct measured 85% and 131%, which is the same band once you account for the error bars. MapStruct is roughly 141 times faster than Dozer on the flat object and 101 times on the nested one.

How far to trust these numbers. They came from a 2-vCPU shared sandbox (see output/00-environment.txt) that was running other work at the same time, and the error bars of the fast cases are large. Trust the order of magnitude — a hundred times or more between Dozer and the rest — and do not trust the second digit, or the small differences between manual and MapStruct (the nested pair even reads as MapStruct ahead of hand-written code, which is noise, not a result). Run ./scripts/run-benchmark.sh on a quiet machine of your own before quoting any figure. And remember what a mapping microbenchmark does not measure: a mapper that takes a microsecond is irrelevant next to the database call it sits beside.
Methodology and what the benchmark does and does not do
  • What is mapped. Samples.flat() (3 fields) and Samples.nested() (a profile and five tags) into UserEntity, DTO to entity only. Inputs are built once and never mutated; each benchmark returns its result so JMH consumes it.
  • Dozer configuration. The same DozerSetup.standard() used everywhere else, built once in @Setup. Dozer parses class metadata lazily on first use; the warmup iterations cover that.
  • The antipattern. dozerNewMapperPerCallFlat calls DozerSetup.standard() on every invocation, which is what “a new mapper per request” means.
  • Not measured. Memory and GC, startup time, the entity-to-DTO direction, MapStruct with componentModel = "spring", and anything under a real framework. JMH also reported that this JVM uses experimental compiler blackholes; the numbers are comparable with each other, not with benchmarks run under a different blackhole mode.
  • Reproduce. ./scripts/run-benchmark.sh; extra arguments go straight to JMH. For a JMH introduction see Java Parallel Streams: When They’re Slower (JMH Benchmarks and the Common Pool) and the JMH samples.

Dozer vs MapStruct: a decision guide

Performance and failure timing are only two of the dimensions. This is the original comparison table, updated for the versions tested and with the cells that this post could verify now backed by output on this page:

FeatureDozer 7.0.0MapStruct 1.6.3
Mapping approachRuntime reflectionCompile-time code generation
Performance (measured here)about 0.6% (flat) and 1.3% (nested) of hand-writtenwithin the noise of hand-written code
Setup complexityLow — no build plugin neededMedium — requires an annotation processor
Type-mismatch configProgrammatic API or XMLAnnotations on a mapper interface, plus plain default methods
Null handlingCopies null by default; TypeMappingOptions.mapNull(false) to skipCopies null by default; NullValuePropertyMappingStrategy.IGNORE on update methods
Compile-time safety❌ A typo fails at mapper build; an unmapped field fails never✅ Build-time errors, including unmapped targets with ReportingPolicy.ERROR
Deep/nested mapping✅ Automatic✅ Automatic for matching property names; @Mapping for the rest
Bidirectional✅ One config (but see the list-converter trap)⚠️ Two mapper methods, or @InheritInverseConfiguration(name = ...)
Java records❌ Cannot map into; mapping from copies nothing✅ Both directions
Spring injection✅ @Bean / @Component✅ @Mapper(componentModel = "spring")
Active maintenanceNo — 7.0.0 (March 2024) is the latest; README says inactiveYes — 1.6.3 GA, 1.7.0 betas on Central

When to choose Dozer

  • You are maintaining a legacy codebase already using Dozer — migration cost outweighs the performance gain for non-critical paths.
  • Your models are not annotation-friendly (e.g., third-party classes you cannot modify) — Dozer can map them without touching the source or destination class.
  • You need very dynamic, runtime-configurable mappings that change based on application state or tenant context.
  • The mapped objects are on a non-critical path (admin screens, batch jobs, infrequent reports) where the throughput gap is irrelevant. Be honest about that last point: at the measured rate Dozer still manages on the order of a hundred thousand mappings a second on this machine, which is plenty for those paths. What you give up is headroom, not the ability to map.

When to choose MapStruct

  • You are building a new project and can set up the annotation processor from day one. Dozer’s own README discourages it for new projects.
  • Performance is critical — high-throughput APIs where mapping runs on every request benefit from near-manual speed.
  • You want compile-time safety — MapStruct fails the build if a target field has no mapping source, catching errors before they reach production (with the policy enabled, as above).
  • You prefer readable, debuggable generated code — MapStruct’s output is plain Java you can step through in a debugger.

Migrating from Dozer to MapStruct without a big-bang rewrite

Because the two libraries are independent and sit happily on the same classpath, you can move one mapper at a time. The risk in a migration is not the new code; it is that the new mapper quietly differs from the old one in some field nobody looked at. So the first deliverable is not a MapStruct mapper, it is a test that proves they agree.

1. Add MapStructprocessor next to Dozernothing changes yet2. Parity testsame inputs throughDozer, MapStruct, manual3. Swap one mapperinject the MapStructone, keep the rest4. Delete Dozerwhen nothing injectsMapper any moreStep 2 is what makes step 3 safe: the test fails the moment the two libraries disagree about any field.

The four steps, left to right. Step 2 is the safety net for step 3: nothing is swapped until the parity test is green, and the test goes on guarding the mapper afterwards. Here is the build setup for step 1, from the module’s pom.xml (the processor goes in annotationProcessorPaths, not in dependencies):

<annotationProcessorPaths>
  <path>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-processor</artifactId>
    <version>${mapstruct.version}</version>
  </path>
  <path>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-generator-annprocess</artifactId>
    <version>${jmh.version}</version>
  </path>
</annotationProcessorPaths>

Step 2, the parity test, from BeanMappingClaimsTest.java. It maps the same three inputs (flat, nested, and one with nulls) through hand-written code, Dozer and MapStruct and asserts all three produce equal entities:

void dozerMapStructAndManualAgreeOnDtoToEntity() {
    Mapper dozer = DozerSetup.standard();
    for (UserDTO in : INPUTS) {
        UserEntity expected = ManualMapper.toEntity(in);
        assertEquals(expected, dozer.map(in, UserEntity.class), "dozer vs manual for " + in);
        assertEquals(expected, UserMapper.INSTANCE.toEntity(in), "mapstruct vs manual for " + in);
    }
}

The hand-written ManualMapper (ManualMapper.java) is the referee. It is dull on purpose: when Dozer and MapStruct disagree, you want a third opinion that is obviously right. Its reverse-direction twin, dozerMapStructAndManualAgreeOnEntityToDto, is what found the list-converter bug above: it failed until the field-level converter existed. Step 3 is mechanical once the test is green. Because both libraries coexist, as the original FAQ said, you can introduce MapStruct for new, performance-sensitive mapping paths and migrate legacy Dozer mappings incrementally.

Translation table: Dozer concept to MapStruct equivalent
In DozerIn MapStructWhere it is in this module
DozerBeanMapperBuilder.buildDefault() singleton beanan interface annotated @Mapper; Mappers.getMapper(...) or componentModel = "spring"UserMapper
.fields("email", "emailAddress")@Mapping(source = "email", target = "emailAddress")DozerSetup vs UserMapper
DozerConverter<A, B>a default method B toB(A a) on the mapper, picked by typeStringToTagConverter vs toTag/fromTag
field-level customConverter for a listusually nothing: the element method is applied to list elements automaticallyTagListConverter
bidirectional by default@InheritInverseConfiguration(name = "...")UserMapper
TypeMappingOptions.mapNull(false)@BeanMapping(nullValuePropertyMappingStrategy = IGNORE) on an update method with @MappingTargetUserMapper update
.exclude("orders")@Mapping(target = "orders", ignore = true)LazyMapper
no warning on unmapped fieldsunmappedTargetPolicy = ReportingPolicy.ERRORUserMapper
XML mapping filesno equivalent; mappings live in the interfacenot covered here
Expect differences, and decide them on purpose
  • Silent nulls become decisions. Every field the Dozer mapper silently skipped will show up as an unmapped-target error. Some of those are real bugs; some are fields you meant to leave alone. Mark the second kind with @Mapping(target = "x", ignore = true).
  • Same-named properties are still matched by name. MapStruct generates nested mapping methods for matching types (as toEntity(ProfileDTO) above), the way Dozer recursed.
  • Collections of converters. The two-direction list trap does not exist in MapStruct: the same toTag/fromTag pair covers both directions, which the parity test confirmed.
  • Dynamic mappings do not migrate. If you chose Dozer for mappings configured at runtime, MapStruct is the wrong tool for those; keep Dozer there or write the logic by hand.

Key best practices for Dozer

  • Singleton Mapper: Create once, reuse everywhere. Never instantiate inside a loop or per-request. The measured cost is above.
  • Exclude heavyweight fields: If your entity has Hibernate-managed lazy collections, configure field exclusions so Dozer does not trigger unintended database queries by calling the getter.
  • Guard against null IDs: When mapping DTOs back to entities for updates, ensure the entity ID is preserved and not overwritten with null from the DTO.
  • Version-lock your dependency: Dozer 7.0.0 is the current release and the project is inactive, so pin the version explicitly in your POM.
  • Build the mapper at startup and test every mapping: a field typo fails when the mapper is built, and a forgotten field fails never. A parity or round-trip test is the only thing that catches the second kind.

Frequently asked questions

Q1: Is Dozer still maintained in 2026?

Barely. The first version of this answer said 6.5.0 (2021) was the final release; that was wrong. 6.5.2 (2021-04-07) and 7.0.0 (2024-03-05) came after it, and 7.0.0 is what this post ran. But the README itself calls the project not currently active and likely to be deprecated, and advises against it for new projects. For existing projects it works for the plain-POJO cases tested here on JDK 25; I did not test Spring Boot. See the maintenance section above.

Q2: Does Dozer work with Java Records?

No, in either direction, and the failure modes differ. As a destination it throws because a record has no no-arg constructor. As a source it throws nothing and copies nothing, because record accessors are not JavaBean getters. Both are in output 02. For records use MapStruct, which supports them directly, or write a factory method.

Q3: How does Dozer handle null source values?

By default it copies them: a null in the source sets the destination field to null. To skip nulls, pass TypeMappingOptions.mapNull(false) as the third argument to mapping(...) (the chained form shown in the first version of this post does not exist in 7.0.0). That is the right setting for partial updates. Output in output 01, sections 5 and 6.

Q4: Will Dozer trigger Hibernate lazy loading on entity fields?

Yes, whenever the destination class has a property of the same name, because Dozer calls the getter. Outside a session that is a LazyInitializationException; inside one it is a hidden query. Exclude the field, or map inside the transaction. The demonstration here uses a simulated lazy getter rather than Hibernate itself, and it shows that MapStruct calls the getter too unless the property is ignored. See the lazy-getter panel above.

Q5: Can I use Dozer and MapStruct together in the same project?

Yes. They are independent libraries with no conflicts; this module has both on one classpath and the parity test runs them against each other. A common migration strategy is to introduce MapStruct for new, performance-sensitive mapping paths while leaving existing Dozer mappings in place, then migrate the rest incrementally. Both can be Spring beans injected by interface or type without interference (the Spring files above show both styles).

Should you even adopt Dozer today? For a new project, no: the library is inactive, the measured cost is two orders of magnitude, and its worst failure mode (a field that silently stays null) is the one MapStruct can turn into a compile error. Use it only to keep an existing codebase running, or where you truly need runtime-configured mappings on a cold path. And if your mapping code is a dozen fields that rarely change, hand-written code is a perfectly respectable answer; the parity test above uses it as the referee for a reason.

Conclusion

Dozer remains a mature bean mapper that dramatically reduces DTO-to-entity boilerplate in Java applications. Its convention-over-configuration approach means that identical fields map automatically, nested objects are handled recursively without extra code, and collections are converted with minimal configuration. The trade-offs are larger than the first version of this post said: measured on JDK 25, Dozer ran at about 0.6% of hand-written code on a flat object and 1.3% on a nested one, MapStruct kept up with hand-written code, and Dozer’s mistakes surface late (a typo at startup) or never (a forgotten field). For legacy codebases and cold paths Dozer still works; for anything new, MapStruct is the safer default, and the parity test makes the move from one to the other a series of small, checkable steps.

Further reading and cross-references

No Comments yet!

This site uses Akismet to reduce spam. Learn how your comment data is processed.