GeeCON Prague 2014*
The moose likes Java in General and the fly likes Creation of objects and serialzation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Creation of objects and serialzation" Watch "Creation of objects and serialzation" New topic
Author

Creation of objects and serialzation

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
ok.. so I have an object that implements serializable. If this object contains other objects, do these internal objects need to be serializable in order to make it all serializable or does the parent implementing serializable automatically apply it to everything.


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780

For an instance of A to successfully serialize, field b must either be null or reference an object that is an instance of a serializable class. Perhaps B implements/extends Serializable or the object referenced is an instance of a subclass of B which itself implements Serializable. A common case of this would be if B were an interface that does not extend Serializable, say List.

There is no automatic transference of serializability to fields in Java, as you may have been hoping for

Field c is guaranteed to work because it is transient. This may require you to implement a writeObject/readObject method. See the API for Serializable.


There is no emoticon for what I am feeling!
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
So in other words, I need to have all objects that are IN a serialized object also be serializable in order to serialize it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creation of objects and serialzation