Backend Development 10 min read

Which Java Bean Mapping Tool Is Fastest? Spring BeanUtils vs MapStruct vs Others

This article compares the performance of several Java bean‑mapping utilities—including Spring BeanUtils, Apache BeanUtils, Orika, Cglib BeanCopier, ModelMapper, MapStruct, and manual getter/setter code—by converting a sample Entity to a DTO 10,000 times and summarizing the results and best‑use recommendations.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Which Java Bean Mapping Tool Is Fastest? Spring BeanUtils vs MapStruct vs Others

1. Introduction

In project development, converting an Entity to a DTO (Data Transfer Object) is a common requirement, especially in front‑back separation or micro‑service architectures. Entities represent database tables, while DTOs are lightweight objects used for data transfer between layers or services.

The conversion aims to hide business‑logic details, reduce data‑transfer size, improve efficiency and security, and enhance maintainability and scalability.

2. Tools Compared

Spring BeanUtils

Apache BeanUtils

Orika

Cglib BeanCopier

ModelMapper

MapStruct

Getter/Setter (manual)

3. Sample Classes

<code>public class User {
    private Long id;
    private String code;
    private String email;
    private String name;
    private String qq;
    private String table;
    private String address;
    // getters and setters
}

public class UserDTO {
    private Long id;
    private String code;
    private String email;
    private String name;
    private String qq;
    private String table;
    private String address;
    // getters and setters
}

User user = new User();
user.setId(1L);
user.setCode("S0001");
user.setEmail("[email protected]");
user.setName("N");
user.setQq("6666666");
user.setTable("CTO");
user.setAddress("XJ");</code>

4. Performance Tests (10,000 iterations)

Each tool copies the User instance to a UserDTO object 10,000 times and measures the elapsed time.

Spring BeanUtils: 55 ms

Apache BeanUtils: 113 ms

Orika: 24 ms

Cglib BeanCopier: 17 ms

ModelMapper: 145 ms

MapStruct: 25 ms

Getter/Setter (manual): 2 ms

The results show that manual getter/setter code is the fastest, followed by Cglib BeanCopier and Orika, while ModelMapper is the slowest among the libraries.

5. Summary

For most projects, MapStruct offers an excellent balance of speed and type‑safety without requiring runtime reflection, making it a strong choice when performance matters but code generation is acceptable. If absolute maximum speed is required and extra code is acceptable, manual getter/setter remains the quickest. Spring BeanUtils provides a convenient out‑of‑the‑box solution with moderate performance, whereas Apache BeanUtils is noticeably slower.

Choose the tool that best fits your project's performance requirements, development convenience, and maintenance preferences.

JavaDTOSpring BootMapStructCGLIBPerformance TestBean Mapping
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.