• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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.
 
Bartender
Posts: 15741
368
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic