• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of Serialization

 
Gourav Bansal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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.
 
Stephan van Hulst
Bartender
Posts: 6583
84
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Tony Docherty
Saloon Keeper
Posts: 3138
72
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!