java.io.invalidClassException during serializing/deserializing

后端 未结 3 1801
再見小時候
再見小時候 2020-12-07 02:45

I\'ve got an object that im reading and writing to and from fileinputstreams/objectinputstreams and objectinputstreams/objectoutputstreams. I keep

3条回答
  •  生来不讨喜
    2020-12-07 02:57

    As stated in documentation this can happen for three different reasons:

    • The serial version of the class does not match that of the class descriptor read from the stream
    • The class contains unknown datatypes
    • The class does not have an accessible no-arg constructor

    So, first of all check that both implementations have the same serialVersionUID. If this is true you have to be sure that the class doesn't use any type that is undefined (or unknown) to the JVM you are trying to deserialize into. Finally you need to provide a standard constructor ClassName() which does empty initialization.

    These can be the problems and surely it's one of these, so I don't think you should look forward something weird. From my personal experience I can add also that using different JVM versions to serialize and deserialize can create this problem, so be sure of it too.

提交回复
热议问题