本文介绍了如何摆脱InvalidClassException SerialVersionUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中保存了一个java对象,然后几天后我改变了我的jre版本。
现在,当我试图读取同一个对象时,我遇到异常:

I had saved one java object in the Database and then after few days I changed my jre version.Now when i tried to read that same object I am getting following exception:

Exception in thread "main" java.io.InvalidClassException:
SerializeMe; local class incompatible: stream classdesc
serialVersionUID = -6377573678240024862, local class serialVersionUID = -8204757486033751616

我怎么能摆脱这个,怎样才能得到保存的物品?

How can I get rid of this,how can I get the saved object?

请帮助我。

推荐答案

如果您可以影响此类的源代码并且JRE只是发生了变化,那么很可能您仍然可以反序列化由旧JVM序列化的对象。只需在类中定义以下字段进行反序列化:

If you can affect source code of this class and JRE was only thing that changed, most likely you can still deserialize object that was serialized by older JVM. Just define following field in class to be deserialized:

private static final long serialVersionUID = -6377573678240024862L;

这篇关于如何摆脱InvalidClassException SerialVersionUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 08:29