Java Reference
In-Depth Information
fault serialization and then add the necessary setup for hash . The read
and write invocations of these methods could have been replaced with
a simple invocation of methods that perform default serialization and
deserialization:
private void writeObject(ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
hash = name.hashCode();
}
In fact, as you may have surmised, given that writeObject performs
nothing but default serialization, we need not have implemented it at
all.
A writeObject method can throw NotSerializableException if a particular
object is not serializable. For example, in rare cases, objects of a class
might be generally serializable, but a particular object might contain
sensitive data.
You will occasionally find that an object cannot be initialized properly
until the graph of which it is a part has been completely deserialized.
You can have the ObjectInputStream invoke a method of your own devis-
ing by calling the stream's registerValidation method with a reference
to an object that implements the interface ObjectInputValidation . When
deserialization of the top-level object at the head of the graph is com-
plete, your object's validateObject method will be invoked to make any
needed validation operation or check.
 
Search WWH ::




Custom Search