Reference article:

www.hollischuang.com/archives/53…

Common Java property replication tools

1.Spring BeanUtils

Advantages: Spring comes with no additional dependencies; High efficiency

Disadvantages: Runtime bean mappings are generated, and code-level errors are deferred until runtime exposure

2.Cglib BeanCopier

Advantages: High performance

3.Apache BeanUtils

Disadvantages: Low performance

4.Apache PropertyUtils

Disadvantages: Low performance

5.Dozer

Advantages: Well integrated with Spring, attributes can be mapped through configuration files, etc

Disadvantages: Low performance

6.MapStruct

Reference article: juejin.cn/post/685921…

Advantages: Fast performance, native based, compile time generation of bean maps, ensuring high performance, problems exposed in advance

Disadvantages: Cumbersome configuration, each kind of data conversion needs to add a convert interface

Performance comparison

Utility class

This operation takes 1000 times

This operation takes 10000 times

The execution time is 100000 times

The execution time is 1000000 times

Spring BeanUtils

5ms

10ms

45ms

169ms

Cglib BeanCopier

4ms

18ms

45ms

91ms

Apache PropertyUtils

60ms

265ms

1444ms

11492ms

Apache BeanUtils

138ms

816ms

4154ms

36938ms

Dozer

566ms

2254ms

11136ms

102965ms

MapStruct

             0ms

                1ms

                      3ms

                       6ms

In summary, we can basically conclude that Spring BeanUtils and Cglib BeanCopier perform well in terms of performance, while Apache PropertyUtils, Apache BeanUtils and Dozer perform poorly.

Conclusion:

Spring BeanUtils/Cglib BeanCopier is recommended if performance is not required

MapStruct is recommended if you have performance requirements and want errors exposed at compile time

Apache PropertyUtils and Apache BeanUtils are not recommended and Dozer has not been updated and maintained for a long time