Deserialization of child classes  
Author Message
Richard Chrenko





PostPosted: 2003-10-28 20:30:00 Top

java-programmer, Deserialization of child classes How does one deserialize an object of subclass B (derived from superclass
A) if both require custom deserialization?

Does Java call only the readObject() Method of B, thus requiring me to
manually call super.readObject() to carry out the custom deserialization of
the superclass?

Or does Java call A.readobject() after instantiating superclass A and
subsequently call B.readObject() after instantiating the additional content
of subclass B?
 
Lothar Kimmeringer





PostPosted: 2003-10-29 1:05:00 Top

java-programmer >> Deserialization of child classes On Tue, 28 Oct 2003 13:29:47 +0100, Richard Chrenko wrote:

> How does one deserialize an object of subclass B (derived from superclass
> A) if both require custom deserialization?
>
> Does Java call only the readObject() Method of B, thus requiring me to
> manually call super.readObject() to carry out the custom deserialization of
> the superclass?

readObject is private, so it's not possible to call super.readObject(...).
If you implement java.io.Serialiable, all readObject-methods that
might exist, will be called by the VM. If you implement
java.io.Externalizable, you're responsible that all readExternal-
methods of superclasses are called. Because readExternal is
public it's not a problem to call super.readExternal(...)

> Or does Java call A.readobject() after instantiating superclass A and
> subsequently call B.readObject() after instantiating the additional content
> of subclass B?

The VM should go from the uppermost class (in your example A)
to the lowermost class (in your example B).


Regards, Lothar
--
Lothar Kimmeringer E-Mail: email***@***.com
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!