-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GenericJackson2JsonRedisSerializer
can't deserialize previously serialized Stream.toList()
#2697
Comments
Would you mind attaching the full stack trace? |
Oh yes sorry i've forgotten, here it is. In debug mode, I can see a difference between the two serialized values :
|
The difference between the two values is that the On the other side, we attempt to preserve custom collection types when reading arrays. Unfortunately, all we have to read the serialized value is The suggested workaround is to wrap the resulting value in a value object instead of caching the top-level value. Paging @christophstrobl for further insights. |
I have implemented a workaround like this : @Cacheable
public List<Integer> getValue() {
return new ArrayList<>(result.stream().toList());
} Instead of this : @Cacheable
public List<Integer> getValue() {
return result.stream().toList();
} But still, i thought it was a good idea to open an issue because the error is difficult to detect : the execution was not stopped by any exception, the only impact is that the Also, even if I understand why this is raising an error, in my opinion a serializer should not serialize something that he won't be able to deserialize, don't you think ? |
I fully agree, I just do not have an idea how to tackle top-level arrays as we don't seem to have sufficient hooks to either always or never enable typing. |
GenericJackson2JsonRedisSerializer
can't deserialize previously serialized Stream.toList()
I reproduced this problem in the following test case method that I am currently adding to the @Test // GH-2697
void serializingDeserializingIntegerListIsHandledCorrectly() {
GenericJackson2JsonRedisSerializer redisSerializer =
new GenericJackson2JsonRedisSerializer();
List<Integer> integers = Stream.of(2953).toList();
//List<Integer> integers = List.of(2953);
//List<Integer> integers = new ArrayList<>(Stream.of(2953).toList());
//List<Integer> integers = new LinkedList<>(List.of(2953));
Object deserializedIntegers =
redisSerializer.deserialize(redisSerializer.serialize(integers));
assertThat(deserializedIntegers)
.isInstanceOf(List.class)
.asInstanceOf(InstanceOfAssertFactories.type(List.class))
.extracting(list -> list.get(0))
.isEqualTo(2953);
deserializedIntegers =
redisSerializer.deserialize(redisSerializer.serialize(deserializedIntegers));
assertThat(deserializedIntegers)
.isInstanceOf(List.class)
.asInstanceOf(InstanceOfAssertFactories.type(List.class))
.extracting(list -> list.get(0))
.isEqualTo(2953);
} Clearly, you can see that I am playing around with different combinations of
What many developers fail to realize is that the This leads to many surprises when users try to use the Additionally, as @mp911de pointed out, these I agree with Mark. I think we have room for improvement, but I am not exactly certain what that is yet. I will continue to think on this next week and talk with both @mp911de and @christophstrobl about possible ideas. |
The issue is that ImmutableListN is a final class it does work if you use I also found an alternative using Guava ImmutableList instead of Java ImmutableListN and
then add I do wish it would work with out either of these workarounds. Does anyone else have suggestions? |
修复 toList 无法进行反序列化问题 spring-projects/spring-data-redis#2697
Hi there,
I'm facing an issue with the
GenericJackson2JsonRedisSerializer()
when using a@Cacheable
annotation on a method returning a List resulting of aStream.toList()
operation.I can easily reproduce with the following unit test :
Please tell me if i'm doing something wrong.
SpringBoot version : 3.1.3
Stacktrace :
The text was updated successfully, but these errors were encountered: