views:

202

answers:

11

How many software projects have you worked on used object serialization? I personally never came across a scenario where object serialization was used. One use case i can think of is, a server software storing objects to disk to save memory. Are there other types of software where object serialization is essential or preferred over a database?

+4  A: 

I've used object serialization in a lot of my projects. Sometimes we use it to store computer-specific settings locally. I have also used XML serialization to simplify interaction and generation of XML documents. It is also very beneficial in communication protocols. Serialize on one end and re-inflate on the other end.

Adam Driscoll
Yes - user config settings in cookies for example. A lot of cookie data is serialization. JSON is another serialization protocol.
le dorfier
+1  A: 

you can combine db & serialization. f.ex. when you have to store an object with a lot of attributes (often dynamic, i.e. one object attribute set will be different from another one) to the relational DB, and you don't want to create a new column per each attribute

zed_0xff
+2  A: 

I'm using serialization to pass objects across a TCP socket. You put XmlSerializers on either side, and it parses your data into readily available objects. If you do a little ground work, you can get it so that you're basically passing objects back and forth, and it makes socket communication extremely easy, reducing it to nothing more than socket.Send(myObject);.

Daniel Rasmussen
Yup, this seems like a scenario where object serialization is essential. Similarly, when a EJB container serves objects to a remote client, serialization takes place.
nash
A: 

We started out with a system that serialized all of the thousands of in-memory objects to disk every 15 minutes or so. When that started taking too long we switched over to a mixed mode of saving the objects into a relational db and pickle file (this was a python system btw). Eventually the majority of the data was stored in a relational database. Interestingly, the system was written in such a way that all of the application code couldn't care less what was going on down there. It was all done using XP and thousands of automated tests.

Khorkrak
+4  A: 

Well, converting objects to XML or JSON is a form of serialization that is quite common on the web. I've also worked on a project where objects were created and serialized to a binary file in one application and then imported into another custom application (though that's fragile since it uses C# and serialization has broken in the past between versions of the .NET framework). Also, application settings that have a complex structure may be useful to serialize. I also think remoting APIs use serialization to communicate. Basically, serialization in general is simply a way to store the states of your objects, and this has many different uses.

Matt
+2  A: 

Here are few uses I can think of :

  1. Send an object across network, the most common example is serializing objects across a cluster
  2. Serialize object for (sort of) caching, ie save the state in a file and read it back later
  3. Serialize passive/huge data to a file to minimize the memory consumption and read it back whenever required.
Nrj
A: 

Document based applications such as word processors and vector graphics editors will often serialize the document model to disk when the user invokes the Save command. Serialization is often preferred over complex databases in these apps.

Alexandre Jasmin
A: 

Using serialization saves you time each time you want to implement an import/export functionality.

Every time you need to export your system's data, create backups or store some kind of settings, you could use serialization instead and just save the state of the objects that represent the actual config, data or whatever else.

Only when you need a specific format of the exported/imported data, there is a sense in building a custom parser and exporter/importer.

Serialization is also change-proof. Whenever you change the format of the object that is involved in the exchange functionality, it is automatically exportable and you don't have to change the logic behind your export/import parts.

Karim
Serialization is only change-proof within the code. It should be noted that the resulting data is very fragile.
cobbal
+2  A: 

Interprocess communication is a biggie.

Pierreten
A: 

We used it for a backup & update functionality. It was basically serialized hibernate objects being backed up, then the DB schema is altered through the update and we delivered a helper class that "coverted" the old objects to the new DB schema. This way we had a pretty solid update mechanism that wouldnt break easily and does an automatic backup at the same time.

Stefan Ernst
A: 

I've used XML serialization heavily on one project. The technique was used to persist to database data structures that had no common structure, so the data couldn't be stored directly. I also used serialization to separate application settings that could be changed at runtime.

Grant Palin