Originally posted by William Brogden
------------------------------------------
My guess is that your derived class should have a writeObject method that throws NotSerializableException. Probably the same for readObject.
------------------------------------------
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by ramprasad madathil:
In another words, if your class doesnt implement Externalizable and you have writeObject and readObject methods, they would be quite redundant. Then, on serialization, the writeObject and readObject methods of the ObjectOutputStream and ObjectInputStream respectively are the ones which are invoked. And since your parent class implements 'Serializable', there wouldnt be exceptions thrown.
Serialization of an object can be prevented by implementing writeObject and readObject methods that throw the NotSerializableException. The exception will be caught by the ObjectOutputStream and abort the serialization process.
Originally posted by Ernest
As it turns out, this is not true at all. ObjectOutputStream will indeed call writeObject() if a Serializable class supplies it. It is not necessary to use Externalizable. What Externalizable does is make your class responsible for storing the superclass state as well -- otherwise your writeObject() is expected to save only the most derived class's state.
Get me the mayor's office! I need to tell him about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|