Fixes #3179 – Restore _class metadata for collections in MappingRedisConverter #3188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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