• 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

Serialization

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case I persist the object and later on change the defination of the class, how can retrieve the object in this scenario?

To explain, I've Class Car whose object I persist using java serialization mechanism; later on I go and change the class definition of a Car. Now I want to deserialize the class object. How this scenario should be handled as I've changed the class defination and now want retrive the object but it's stored as per the old class definition.
 
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

Mahesh Bamane wrote:Now I want to deserialize the class object. How this scenario should be handled as I've changed the class defination and now want retrive the object but it's stored as per the old class definition.


The simple answer is: you can't - at least not without writing a converter and probably some very tortuous logic as well.

Serialization does not interact well with change control.

Winston

PS: This page has some ideas on the subject, but my advice would still be: DON'T DO IT. It's a disaster waiting to happen.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do custom serialization using ObjectStreamField, ObjectInputStream.GetFields and ObjectOutputStream.PutFields. An example, taken from StringBuffer:
Also, make sure the two versions have the same serialVersionUID.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic