File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialize a transient object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialize a transient object" Watch "Serialize a transient object" New topic
Author

Serialize a transient object

Lorenzo Tagliaferro
Greenhorn

Joined: Jun 15, 2009
Posts: 20

Hi to all,

I'm not able to serialize a transient object.

I have a non-serializable class, like this:



And another class, that implements Serializable, with a transient object of type Newspaper:



When i de-serialize the Newspaper object i got an NotSerializableException.

How can i serialize the Newspaper class without use Serializable Interface?!

Thank you all!!

John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185

As Newspaper is not serializable you have to do something like:

and then in private void readObject(ObjectInputStream is):

So you have to write and read the fields by hand.


John
Sam Hazim
Greenhorn

Joined: Jul 19, 2011
Posts: 26
And worth noting that Serialization is off scope for the current exam.
Lorenzo Tagliaferro
Greenhorn

Joined: Jun 15, 2009
Posts: 20

Sam Hazim wrote:And worth noting that Serialization is off scope for the current exam.


Good Stuff!!! :-)
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281


Why Serialization is not part of exam even though its one of rarely understood concept among developers ? any guess ?


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
Sam Hazim
Greenhorn

Joined: Jul 19, 2011
Posts: 26
I don't know - I'd like to have seen it remain on the exam to be honest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialize a transient object