Equivalent of C# OnDeserialized/OnSerializaed in Java?
Is there an equivalent to the C# [OnSerialized] and [开发者_C百科OnDeserialized] attributes in Java?
If you're using default Java serialization, you can override the methods used to serialize and deserialize. These methods are:
private void writeObject(ObjectOutputStream out) throws IOException
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
Just call the "default" method for each of these: out.defaultWriteObject(out) and in.defaultReadObject(in).
There's a very detailed article on Java serializtion at http://java.sun.com/developer/technicalArticles/Programming/serialization/
精彩评论