Skip to content

Add Envers generic‑type handling for JSON collections #838#841

Open
gebhardt wants to merge 1 commit intovladmihalcea:masterfrom
gebhardt:feature/838_EnversGenericTypeHandlingForJsonCollections
Open

Add Envers generic‑type handling for JSON collections #838#841
gebhardt wants to merge 1 commit intovladmihalcea:masterfrom
gebhardt:feature/838_EnversGenericTypeHandlingForJsonCollections

Conversation

@gebhardt
Copy link
Copy Markdown

(detailed message generated by Claude Opus 4.6)
When Hibernate Envers builds audit entity mappings, JavaXMember.getJavaType() returns only the raw Class (e.g. List.class) instead of the full ParameterizedType (e.g. List). This causes Jackson to deserialize JSON collections as LinkedHashMap objects instead of the expected POJO type.

This commit applies three fixes to JsonJavaTypeDescriptor:

  1. Constructor fix: The (ObjectMapperWrapper, Type) constructor now extracts the raw type from a ParameterizedType before passing it to the superclass, allowing subclasses to provide the full generic type via TypeReference.

  2. setParameterValues guard: When propertyType is already a ParameterizedType (e.g. set by a constructor), it is no longer overwritten with a less specific raw Class from Envers.

  3. Reflection fallback: When setParameterValues receives only a raw Collection or Map type, the full generic signature is recovered by reflecting on the entity field using DynamicParameterizedType.ENTITY and DynamicParameterizedType.PROPERTY.

Root cause: Envers loses generic type information when constructing synthetic JavaXProperty instances for audit entities. This should additionally be reported as a bug against Hibernate ORM / Envers.

(detailed message generated by Claude Opus 4.6)
When Hibernate Envers builds audit entity mappings, JavaXMember.getJavaType()
returns only the raw Class (e.g. List.class) instead of the full
ParameterizedType (e.g. List<MyType>). This causes Jackson to deserialize
JSON collections as LinkedHashMap objects instead of the expected POJO type.

This commit applies three fixes to JsonJavaTypeDescriptor:

1. Constructor fix: The (ObjectMapperWrapper, Type) constructor now extracts
   the raw type from a ParameterizedType before passing it to the superclass,
   allowing subclasses to provide the full generic type via TypeReference.

2. setParameterValues guard: When propertyType is already a ParameterizedType
   (e.g. set by a constructor), it is no longer overwritten with a less
   specific raw Class from Envers.

3. Reflection fallback: When setParameterValues receives only a raw
   Collection or Map type, the full generic signature is recovered by
   reflecting on the entity field using DynamicParameterizedType.ENTITY
   and DynamicParameterizedType.PROPERTY.

Root cause: Envers loses generic type information when constructing
synthetic JavaXProperty instances for audit entities. This should
additionally be reported as a bug against Hibernate ORM / Envers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant