• 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

Use of Serialization

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serialization is to Store the Object state or Object Variable Data to Stream or File and Deserialize later on.

I can achieve this by writing the Object variable Data to File and send it someone else and the other Application read the file and do processing. It might be tedious to write and read the file as compared to Serialization but still I can do that.

Is there any specific purpose we should choose Serialization ?? Please correct me if I misunderstood something.
 
Saloon Keeper
Posts: 15630
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some libraries expect types to be Serializable in order to transform them to different formats, such as XML, JSON or database entries. For large object graphs, it can also be relatively quick to make all involved objects Serializable when you want to write them to a file.

In general though, I don't think the cost is worth it. Making a type Serializable means you have to think about a *lot* of things that can possibly go wrong, and it's easy to make mistakes in your implementation.

Most of the time I prefer to make "repository types" that are responsible for storing my objects somewhere, usually using a BufferedWriter to write them to a simple text file.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also some technologies such as RMI rely heavily on Serialization.

For transitory state operations such as passing the state of an object over a network then Serialisation is useful but for saving an objects state I wouldn't use Serialization. As Stephan has said there are a number of things that can go wrong especially if your classes have changed (eg by fixing a bug, adding a new feature etc) between writing the serialised data and reading it.
reply
    Bookmark Topic Watch Topic
  • New Topic