I stored data using the following code (and it inherited the serial example a): class A implementation serializable {Private static last long serialvarsion UID = 1 L; Int someField; BB; } Implementation of Class B Serializable {Private Static Last Long Serialvarsion UID = 1 L; Int someField; } At some point I realized that
A
should not actually be in the b
area (and the B < / code> Siriylaij should not be able to), so I changed it to things:
class a implementations Serializable {Private static final long serialVersionUID = 1L; Int someField; Transient BB; } Class {int someField; }
If I create a new instance of A
and we serialize it, then I have no problem deserializing it. However, if I have to has been stored with a
that old code, I tried to deserialize instances get an exception form:
java.io .invalidClassException: b; B; Java.io.oobjectstreamclass.checkDeserialize on deserialization to invalidate the classroom (java.io.O.ObjectInputStream.readObject0 at Java_io.ObjectInputStream.readOrdinaryObject (unknown source). Unknown (unknown source). Java.io.ObjectInputStream.defaultReadFields unknown source (unknown source) JavakiokObjectInputStreamkreadSerialData (unknown source java.io.ObjectInputStream.readOrdinaryObject on java.io.ObjectInputStream.readObject0 on JavakiokObjectInputStreamkreadObject) (unknown source) (unknown source) (unknown Source)
I believe this is the same as the A
in the continuous data The class description of b
is stored, and they still think that b
is similar, even if they are now in the current version
There is a way to force the ordering of one drop over areas (see for 600 in 600 lines) that are transient now? For example, so it is a way to update override his momentary knows class description that reads deserialization code ObjectInputStream in
and b
to your definition?
In fact, (almost) any Changes that you make in the source code of the classroom, will make the old serial data deserialize impossible. The serialization connects your source code very tightly into the ordering data.
This is the reason that the serialization is not favorable for long-term data collection. Serialization is only suitable for things like RMI (transporting objects on the network) or temporary storage on disk. Use the (standard) file format instead of Java numbering for a well-documented long-term data storage.
Deserialize the data using the old code, what you can do, then write it in another format, and then only use that format.
Comments
Post a Comment