I am using spring-session-data-redis , spring-boot-starter-data-redis for session persistence in Redis. The springboot version for the application is 3.2.6
I am also using springboot security with OAuth2 for login.
Here is the following Redis session configurationg to serialize/deserialize session data to/from Redis.
@Bean
public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
return new GenericJackson2JsonRedisSerializer("_classType");
}
But on trying to login to the application I am receiving the following error
org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Cannot construct instance of `org.springframework.security.web.savedrequest.DefaultSavedRequest` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (byte[])"{"_classType":"java.util.HashMap","lastAccessedTime":["java.lang.Long",1721629583744],"maxInactiveInterval":3300,"creationTime":["java.lang.Long",1721629583744],"sessionAttr:SPRING_SECURITY_SAVED_REQUEST":{"_classType":"org.springframework.security.web.savedrequest.DefaultSavedRequest","cookies":["java.util.ArrayList",[{"_classType":"jakarta.servlet.http.Cookie","name":"XSRF-TOKEN","value":"509d859a-215f-408e-85f9-30515ce4ab12","attributes":{"_classType":"java.util.Collections$UnmodifiableMap",""[truncated 1126 bytes]; line: 1, column: 288] (through reference chain: java.util.HashMap["sessionAttr:SPRING_SECURITY_SAVED_REQUEST"])
at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:292) ~[spring-data-redis-3.2.6.jar:3.2.6]
at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:261) ~[spring-data-redis-3.2.6.jar:3.2.6]
at org.springframework.session.data.redis.RedisIndexedSessionRepository.onMessage(RedisIndexedSessionRepository.java:573) ~[spring-session-data-redis-3.2.3.jar:3.2.3]
at org.springframework.data.redis.listener.RedisMessageListenerContainer.processMessage(RedisMessageListenerContainer.java:818) ~[spring-data-redis-3.2.6.jar:3.2.6]
at org.springframework.data.redis.listener.RedisMessageListenerContainer.lambda$dispatchMessage$23(RedisMessageListenerContainer.java:976) ~[spring-data-redis-3.2.6.jar:3.2.6]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
I tried configuring the serializer as per the spring docs, but that didnt work
Can anyone help me with this issue?