Related to Serialization

Q

qazmlp1209

public class myClass implements Serializable
{
private int intData ;
private String stringData ;
private myEnum enumData ;
private Collection<someOtherClass> someOtherObjCol ;

// Other parts

static final long serialVersionUID = 1L;

}

My understanding is given below, to make myClass objects eligible for
serialization:
- int, String data are serializable by default. So, nothing
additionally needs to be done for them.
- All enum(introduced in Java 1.5) objects are serializable by
default. So, nothing additionally needs to be done for them.
- someOtherClass should implement the Serializable.

So, to make myClass objects serializable, I should just make
someOtherClass objects to be Serializable.
I assume no other changes are required.

Can anybody confirm this?
 
B

Bart Cremers

An extra thing is you need to make sure the Collection implementation
used implements Serializable. This goes for all standard collection
classes in the jdk, but if you happen to use a custom implementation
you migth get errors (Collection does not extend Serializable!!).
Further, you need to make sure that every member proeprty of
someOtherClass also is serializable or declared transient, and so on
and so on.

Regards,

Bart
 

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,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top