Serialization in Java, invalid type code 00

前端 未结 4 1194
别跟我提以往
别跟我提以往 2020-12-20 18:34

I\'m getting an error (java.io.StreamCorruptedException: invalid type code: 00) when reading in a serialised object. Here is the class that implements serializable:

4条回答
  •  借酒劲吻你
    2020-12-20 19:08

    You have implemented a recursive writeObject method: when you write an instance to an output stream, it calls the writeObject method, which writes an int, and then writes the object to the output stream, which write an int, etc.

    The goal of the serialVersionUID field is to check that the objects are compatible. It's done natively by the serialization mechanism. You don't have to do anything except changing the serialVersionUID value when the class changes.

提交回复
热议问题