之前存入Redis中的数据再次取时同时出现
SerializationFailedException和InvalidClassException
Cannot deserialize;
nested exception is org.springframework.core.serializer.support.SerializationFailedException:
Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?;
nested exception is java.io.InvalidClassException: com.crazyape.other.entity.Notice;
local class incompatible:
stream classdesc serialVersionUID = 8655127975488226493,
local class serialVersionUID = 5860155642145136340
org.springframework.data.redis.serializer.SerializationException:Cannot deserialize;
nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload.
Is the byte array a result of corresponding serialization for DefaultDeserializer?;
nested exception is java.io.InvalidClassException: com.crazyape.other.entity.Notice;
local class incompatible: stream classdesc serialVersionUID = 8655127975488226493,
local class serialVersionUID = 5860155642145136340
Caused by: java.io.InvalidClassException: com.crazyape.other.entity.Notice;
local class incompatible:
stream classdesc serialVersionUID = 8655127975488226493,
local class serialVersionUID = 5860155642145136340
报异常的主要原因是:
通过序列化存入Redis中的序列数与我反序列化要拿的序列数不一致
换句话说就是存入Redis里的序列数和我创建类的序列数不一致
解决方法:
在操作的实体类中加入静态变量serialVersionUID
private static final long serialVersionUID = 8655127975488226493L;
serialVersionUID的值与序列化时的序列值保持一致
总结:
实现Serializable接口时推荐显式的声明serialVersionUID