mat_boy
mat_boy

Reputation: 13666

Adding object to HttpSession fails in SpringBoot with Redis

When I try to add an object into the session as follows:

HttpSession session = ....
MyObject object = ....
session.setAttribute("my_object", object);

then I get an exception:

org.springframework.data.redis.serializer.SerializationException: 
Cannot serialize; nested exception is   
org.springframework.core.serializer.support.SerializationFailedException:
Failed to serialize object using DefaultSerializer; nested exception is 
java.lang.IllegalArgumentException: DefaultSerializer requires a  
Serializable payload but received an object of type [MyObject]

What should I do to instruct REDIS in serializing the object MyObject?

Upvotes: 1

Views: 1842

Answers (1)

JeanValjean
JeanValjean

Reputation: 17713

I guess that the exception is already telling you what is going wrong. Simply try to make MyObject implementing Serializable

Upvotes: 4

Related Questions