1.代码刚更新就有同事找我报错了
com.voc4cloud.voc.admin.api.dto.UserInfo; local class incompatible: stream classdesc serialVersionUID = -6423749437980912546, local class serialVersionUID = 8189966274600548814`
2.发现: 通过查看日志发现是序列化报错了
3.原因: 因为新增了一个字段 , 而这个类没有写serialVersionUID , 而且这个接口缓存了 , 然后他们请求的时候就报错了
在没有写serialVersionUID 时是通过类名和字段名生成的一个id , 当修改了字段后就会导致id更改 , 所以会报错
4.解决: 删掉缓存 , 并在下次更新的时候在这个类上加上serialVersionUID , 今后实现了Serializable就一定需要写serialVersionUID
参考资料:
讲真,下次打死我也不敢随便改serialVersionUID了
#打开Serializable接口上可以看到如下注释:大概说的就是如果serialVersionUID不同会报错
The serialization runtime associates with each serializable class a version
number, called a serialVersionUID, which is used during deserialization to
verify that the sender and receiver of a serialized object have loaded
classes for that object that are compatible with respect to serialization.
If the receiver has loaded a class for the object that has a different
serialVersionUID than that of the corresponding sender's class, then
deserialization will result in an {@link InvalidClassException}. A
serializable class can declare its own serialVersionUID explicitly by
declaring a field named <code>"serialVersionUID"</code> that must be static,
final, and of type <code>long</code>: