• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creation of objects and serialzation

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in other words, I need to have all objects that are IN a serialized object also be serializable in order to serialize it?
 
reply
    Bookmark Topic Watch Topic
  • New Topic