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
+26
View File
@@ -0,0 +1,26 @@
== 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)
== 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]
== 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=[]]
== 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]
== 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)