Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialize a transient object

 
Lorenzo Tagliaferro
Greenhorn
Posts: 20
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And worth noting that Serialization is off scope for the current exam.
 
Lorenzo Tagliaferro
Greenhorn
Posts: 20
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Hazim wrote:And worth noting that Serialization is off scope for the current exam.


Good Stuff!!! :-)
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why Serialization is not part of exam even though its one of rarely understood concept among developers ? any guess ?
 
Sam Hazim
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know - I'd like to have seen it remain on the exam to be honest.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic