-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
Description
Hello!
Spring Boot Version: 4.0.0-M3
Java: 25
I have an issue when trying to deserialize a String with type information. For example
private static final String JSON_STRING ="""
["java.util.ArrayList",[{"@class":"com.example.redisdemo.RedisdemoApplicationTests$Person","firstName":"firstName","lastName":"lastName"}]]
""";When trying to deserialize the object, an exception is throw when trying to resolve the type. This works with GenericJackson2JsonRedisSerializer.
This is the stacktrace when running a test
[ERROR] com.example.redisdemo.RedisdemoApplicationTests.genericJackson3JsonRedisSerializerTest -- Time elapsed: 0.180 s <<< ERROR!
org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Cannot invoke "tools.jackson.databind.JsonNode.isString()" because "jsonNode" is null
at org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer.deserialize(GenericJackson3JsonRedisSerializer.java:212)
at org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer.deserialize(GenericJackson3JsonRedisSerializer.java:182)
at com.example.redisdemo.RedisdemoApplicationTests.genericJackson3JsonRedisSerializerTest(RedisdemoApplicationTests.java:47)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
Caused by: java.lang.NullPointerException: Cannot invoke "tools.jackson.databind.JsonNode.isString()" because "jsonNode" is null
at org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer$TypeResolver.resolveType(GenericJackson3JsonRedisSerializer.java:482)
at org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer.resolveType(GenericJackson3JsonRedisSerializer.java:222)
at org.springframework.data.redis.serializer.GenericJackson3JsonRedisSerializer.deserialize(GenericJackson3JsonRedisSerializer.java:210)
... 5 moreThis is the code being used to test the issue
private static final String JSON_STRING ="""
["java.util.ArrayList",[{"@class":"com.example.redisdemo.RedisdemoApplicationTests$Person","firstName":"firstName","lastName":"lastName"}]]
""";
private GenericJackson3JsonRedisSerializer createGenericJackson3JsonRedisSerializer() {
return GenericJackson3JsonRedisSerializer.builder()
.customize(builder -> builder
.activateDefaultTyping(
BasicPolymorphicTypeValidator.builder()
.allowIfBaseType(Object.class)
.build(),
DefaultTyping.NON_FINAL,
As.PROPERTY)
.findAndAddModules())
.build();
}
@Test
void genericJackson3JsonRedisSerializerTest() {
var serializer = createGenericJackson3JsonRedisSerializer();
List<Person> listOfPerson = (List) serializer.deserialize(JSON_STRING.getBytes());
assertThat(listOfPerson)
.isNotEmpty()
.contains(new Person("firstName", "lastName"));
}I'm attaching a small application with a test using both GenericJackson2JsonRedisSerializer and GenericJackson3JsonRedisSerializer
Thanks!
soelvar and yurikilian
Metadata
Metadata
Assignees
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged