What is the meaning of serialization in programming languages?

C#.NetSerialization

C# Problem Overview


What is the meaning of serialization concept in programming languages?

when we use Serializable attribute above a class, what is the meaning?

C# Solutions


Solution 1 - C#

Say you have two applications that run on two different physical machines. Both of the applications need to exchange data that is commonly used by both applications. These application talk to each other to share the data with some mediums, these mediums could be a file-system, tcp or udp connections or any other suitable network protocol or may be direct in-memory data exchange. Any of these mediums would only understand data that is described in the form of a series of bits. So when one application needs to send a value 10 to another, the value 10 would be sent as its binary representation 1010 and you would also pass some information that describes 1010. This meta information will also be a series of bits that the other application can easily understand. That was easy though.

Lets take another example, wherein these two apps need to exchange a more complex, non primitive data-type. Lets say they need to exchange the objects of type Book where Book is a custom defined class in your application and both the applications have the definition of type Book.

public class Book
{
    Book() { }

    public long BookId { get;set; }
    public string Author { get;set; }
    public string Title { get;set; }
}

How will you exchange the objects of type book between the two applications? To be able to share the object between two apps, you will need to be able to convert the Book objects into binary representation. This is where serialization comes into the picture.

With the help of Serialization you can define how an object can be converted into its binary representation. The receiving application would do the reverse process, that is De-Serialization, that constructs a Book object from its binary representation.

Solution 2 - C#

There is no better explanation than the one from wikipedia.

> In computer science, in the context of > data storage and transmission, > serialization is the process of > converting a data structure or object > into a sequence of bits so that it can > be stored in a file or memory buffer, > or transmitted across a network > connection link to be "resurrected" > later in the same or another computer > environment.

http://en.wikipedia.org/wiki/Serialization

Also, the Serializable Attribute cannot be used on methods. Indicated by the Attribute Usage

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)]

Solution 3 - C#

Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes.

Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.

more about this : http://www.allinterview.com/showanswers/20627.html

Solution 4 - C#

Serialization is the process in which data translating data structure or object state into a format that can be stored

Solution 5 - C#

Why do we need a serialization?

In procedural language such as Cobol or C there is no concept of serialization. Why do we then use it in OOP? Let us take Java. You have a class which is instantiating multiple classes called Objects, and you want to pass one of those objects state (current values of variables) over network through Message Oriented Middleware in the form of byte stream, and you need serialization and de-serialization. If multiple languages agree on this byte stream format, serialization can even provide a way for otherwise incompatible systems to exchange data.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmasoud ramezaniView Question on Stackoverflow
Solution 1 - C#this. __curious_geekView Answer on Stackoverflow
Solution 2 - C#Pieter GermishuysView Answer on Stackoverflow
Solution 3 - C#Pranay RanaView Answer on Stackoverflow
Solution 4 - C#Ajay PanditView Answer on Stackoverflow
Solution 5 - C#SivaView Answer on Stackoverflow