An object that needs to be serialized should implement Serializable Interface.
Serializable doesn't have any methods but is just a Marker Interface.
All superclasses must implement the Serializable methods for their state to be correctly deserialised.
If superclass doesn't implement Serializable it should have a no-arg default constructor otherwise compiler throws error. In such a case the initilization of superclass (to the expected state) can be done by the Subclass.
If superclass implements Serializable it is initialized to the correct state when the subclass is de-serialized.
To Serialize - call ObjectOutputStream.writeObject( iImplementSeriazable );
To De-Serialize - call objectToRead = ObjectInputStream.readObject( );
To provide custom serialization/deserialisation implement the following methods
private void readObjectNoData() throws ObjectStreamException;
Serializable doesn't have any methods but is just a Marker Interface.
All superclasses must implement the Serializable methods for their state to be correctly deserialised.
If superclass doesn't implement Serializable it should have a no-arg default constructor otherwise compiler throws error. In such a case the initilization of superclass (to the expected state) can be done by the Subclass.
If superclass implements Serializable it is initialized to the correct state when the subclass is de-serialized.
To Serialize - call ObjectOutputStream.writeObject( iImplementSeriazable );
To De-Serialize - call objectToRead = ObjectInputStream.readObject( );
To provide custom serialization/deserialisation implement the following methods
private void writeObject(java.io.ObjectOutputStream out) throws IOException
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException;
private void readObjectNoData() throws ObjectStreamException;
Serializable classes that need to designate an alternative object to be used when writing an object to the stream should implement this special method with the exact signature:
ANY--MODIFIER Object writeReplace() throws ObjectStreamException;
Classes that need to designate a replacement when an instance of it is read from the stream should implement this special method with the exact signature.
ANY--MODIFIER Object readResolve() throws ObjectStreamException;
public interface Externalizable extends Serializable
void readExternal(ObjectInput oi)
void writeExternal(ObjectOutput oo)
No comments:
Post a Comment