改变类型的Libary类的反序列化

时间:2016-03-02 12:05:45

标签: java deserialization jfreechart

我想将JfreeChart 1.0.9更新为1.0.19。 在我的应用程序中,我通过zip中的序列化保存一些对象并加载它我再次反序列化它。 (简单) 现在,当我将JFreeChart更新为新版本时,JfreeChart的DataRange类会给我带来麻烦。

我收到此错误:

public class DateRange extends Range implements Serializable {

    /** For serialization. */
    private static final long serialVersionUID = -4705682568375418157L;

    /** The lower bound for the range. */
    private Date lowerDate;

    /** The upper bound for the range. */
    private Date upperDate;
...

我分析了DateRange的类,并找到了问题。

DateRange.java 1.0.9:

public class DateRange extends Range implements Serializable {

    /** For serialization. */
    private static final long serialVersionUID = -4705682568375418157L;

    /** The lower bound for the range. */
    private long lowerDate;

    /** The upper bound for the range. */
    private long upperDate;
...

DateRange.java 1.0.19:

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
}

你应该看到问题所在。 lowerDate和upperDate字段的类型从java.util.Date更改为long。 现在我无法再次反序列化现有项目。 (对于新项目来说这不是问题)

你有解决方法如何解决它?

我唯一要解决的问题是修改源代码并将以下方法添加到此处解释的DateRange.java中:Serialization

#skip-external-locking 
#bind-address       = 127.0.0.0

但我不想在可能的情况下修改jfreechart。

1 个答案:

答案 0 :(得分:0)

I solved it myself. I changed the DateRange.java and modify the type of lowerDate and upperDate from long to Date. (it's not very nice solution)

With the readObject it didn't work because I get an EOFException when I deserialize the other objects.

When somebody have a better solution I would like to hear it.