Skip to content

What is Serialization?

8 Jul, 12

Definition of Serialization:

Serialization is the process of converting a data structure or object state into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and “resurrected” later in the same or another computer environment. [Wikipedia]

In other words, Object serialization is the process of saving an object’s state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time.

The object is serialized to a stream, which carries not just the data, but information about the object’s type, such as its version, culture, and assembly name. From that stream, it can be stored in a database, a file, or memory.

It lets you take an object or group of objects, put them on a disk or send them through a wire or wireless transport mechanism, then later, perhaps on another computer, reverse the process: resurrect the original object(s). The basic mechanisms are to flatten object(s) into a one-dimensional stream of bits, and to turn that stream of bits back into the original object(s).

Data serialization formats:

These are various ways to convert complex objects to sequences of bits. In .NET, BinaryFormatter  and SoapFormatter are prominently used. You can define your own format too. Some other widely used data serialization formats are JSON, XML-RPC, BSON, YAML etc. Each format is having its encoding and decoding rules.

For more details:

Why it named as Serialization:

Serialization is all about converting objects to raw data. Then how it lends itself towards anything that is related to the term “serial”?

Serialization transforms data in memory with data structures and pointers into a series of bytes designed to be saved on a sequential media, such as a hard disk or transferred through something like a serial connection.

It’s probably from networking and communications, where it is necessary to convert data into a serial stream of ones and zeros. The fact that data is sent to disk or over a network as a “stream” is almost certainly the origin of this term.

Another way to think of it, however, is like this: The state of a program is spread all over memory, with pointers/links pointing all over the place. You have arrays, lists, trees, call stacks, heaps of allocated memory, etc., in no particular order. When you want to save some state, you cannot use much of the information in your program. For example, any pointer values or stack offsets (whether used directly or used internally by the language runtime, etc.) will likely not be valid the next time your program runs because the heap will have been used to allocate slightly different series of memory blocks. Saving these pointer values would be useless. To save some state, you have to “put your affairs in order” such that the information being saved is only that part that will be relevant later on.

Uses of Serialization: 

Serialization allows the developer to save the state of an object and recreate it as needed, providing storage of objects as well as data exchange. Through serialization, a developer can perform actions like:

  1. Sending the object to a remote application by means of a Web Service
  2. Passing an object from one domain to another
  3. passing an object through a firewall as an XML string
  4. Maintaining security or user-specific information across applications
  1. Passing an object from on application to another
  1. Storing user preferences in an object
  2. Modification of XML documents without using the DOM

Are methods also serialized along with the data members?

No. Method bodies do not hold any information on the state of an object, so they are not needed in order to save or restore the state.

Useful links on Serialization:


From → C Sharp

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: