• 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

Doubt in Serializable classes and what we can do with them

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a line in Head FIrst Java 2nd edition that says that we are allowed to add or remove classes in the inheritance tree, without affecting the ability of the objects from a class to be deserialized, but there is another line that says that we should not let the class
whose objects are serialized move up or down in the inheritance tree.

Does this mean that we can only add/delete classes which are 1)at the same level 2)a descendant of the class
with serializable objects

Does this mean that we cannot delete classes that are ancestors of the class whose objects are serialized?(Ofcourse taking the precaution that the child of the deleted ancestor class now becomes the child of the parent of the deleted ancestor class)
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John McDowell wrote:Does this mean that we cannot delete classes that are ancestors of the class whose objects are serialized?


That's what I'd assume. And for the reason, just think about what serialization means:

It means that somewhere, sometime, someone probably saved a copy of an object in a file. And if you ever need to access that copy, you'd better be able to reconstruct it. So if you ever change the structure so that something significant is different, the serialization process will raise an Exception.

That said, the need for inserting or removing classes from a hierarchy is (or should be) pretty rare.

HIH

Winston
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic