Deserialization of child classes

R

Richard Chrenko

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?
 
L

Lothar Kimmeringer

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: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top