Fixes #3179 – Restore _class metadata for collections in MappingRedisConverter#3188
Fixes #3179 – Restore _class metadata for collections in MappingRedisConverter#3188xyraclius wants to merge 1 commit intospring-projects:mainfrom
Conversation
…ections in MappingRedisConverter Signed-off-by: Nabil Fawwaz Elqayyim <master@nabilfawwaz.com>
|
Thank you @xyraclius for looking into this. The type mapper unfortunately will try to create a persistent entity during the type lookup for the user type. This leads to We also might not need to preserve the user type in that detail. |
|
Thank you for your contribution @xyraclius - merged to main development line. |
Overview
This PR resolves a regression in Redis Stream serialization introduced in
spring-data-redis4.0.0-SNAPSHOT, where the_classmetadata is no longer written when serializing collections. As a result, deserialization fails with:The issue is tracked in GitHub issue #3179.
The Problem
In Spring Data Redis
3.5.1, when usingReactiveRedisTemplateto write and read a collection into a Redis Stream, theMappingRedisConvertercorrectly writes the_classmetadata using the configuredtypeMapper. This metadata allows the deserializer to reconstruct the correct types during a read operation.In
4.0.0-SNAPSHOT, an optimization forCollectiontypes bypasses the call totypeMapper.writeType(...), resulting in the_classfield being omitted. This omission breaks deserialization compatibility with existing data and behavior.The Solution
To restore the previous behavior while preserving the new optimization, this PR adds the following line:
Before:
After:
This ensures _class metadata is written for collection values in Redis Streams, restoring compatibility with existing deserialization logic.
Test Coverage
This fix is already verified by the existing test case:
This test verifies that _class metadata is written when serializing collections.
It fails without the fix and passes once the metadata is correctly applied.
Related Issue