bean-mapping: Dozer 7.0.0 vs MapStruct 1.6.3 module (basic/nested/collection/null handling, silent-failure pitfalls, records, lazy getters, parity test, compile-failure demos, JMH benchmark), 14 contract tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
This commit is contained in:
Ankur
2026-12-01 08:19:12 +05:30
co-authored by Claude Sonnet 5.5
parent a714780bca
commit 91f0757259
40 changed files with 2529 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
# bean-mapping
Companion code for the ankurm.com post *"Dozer Bean Mapping in Java: Practical Guide, Pitfalls, a Migration
Path to MapStruct and a Real Benchmark."* Module `bean-mapping` in `java-core-examples`.
All explanation lives in the post; this module holds the runnable evidence and the captured output.
## Versions
| Component | Version |
|---|---|
| JDK | 25.0.5.1+2 (Temurin, LTS) |
| Dozer (`dozer-core`) | 7.0.0 (Maven Central, 2024-03-05; newest release) |
| MapStruct | 1.6.3 (newest GA; 1.7.0.Beta2 exists but is a beta) |
| JMH | 1.37 |
| JUnit Jupiter | 5.11.0 |
## Quickstart
```bash
export JDK25_HOME=/path/to/jdk-25
./scripts/run-all.sh # rebuilds, runs the tests, regenerates everything in output/ (benchmark: ~4 min)
SKIP_BENCHMARK=1 ./scripts/run-all.sh # everything except the benchmark
./scripts/run-benchmark.sh -f 1 -wi 1 -i 1 # a quick benchmark smoke run; extra args go to JMH
```
## What is in here
| File | Shows | Output |
|---|---|---|
| `DozerTour` | basic, nested, collection, bidirectional, null handling, `mapNull(false)` | `01` |
| `DozerPitfalls` | typo in a field name, silently unmapped fields, records, a global converter that is ignored on lists, lazy getters and `exclude` | `02` |
| `MapStructTour` | the same mappings in MapStruct, `@InheritInverseConfiguration`, update with `IGNORE`, records, lazy getters and `ignore` | `03` |
| `UserMapper` | the MapStruct mapper; its generated implementation is captured in output `04` | `04` |
| `src/broken/*.java` | two mappers that do not compile (an unmapped column; an ambiguous inverse); outside the Maven build, driven by `scripts/compile-broken.sh` | `05` |
| `BeanMappingClaimsTest` | 14 assertions behind the claims in the post, including the Dozer / MapStruct / manual parity test used for migration | `06` |
| `MappingBenchmark` | manual vs MapStruct vs Dozer on a flat and a nested object, plus the Dozer mapper-per-call antipattern | `07` |
Timings in `07` depend on the machine and on what else it is running; the order of magnitude between libraries
does not. The `@Generated(date=...)` line in `04` changes on every build. The Spring snippets from the post
(`DozerSpringConfig`, `DozerUserService`, `SpringUserMapper`, `MapStructUserService`) are not in this module;
they are downloadable from the post.