Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of serialization in programming languages? [duplicate]

What is the meaning of serialization concept in programming languages?

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

like image 234
masoud ramezani Avatar asked Jun 15 '10 05:06

masoud ramezani


People also ask

What does serialization mean in programming?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

What is serialization in simple words?

In computing, serialization (US and Oxford spelling) or serialisation (UK spelling) is the process of translating a data structure or object state into a format that can be stored (for example, in a file or memory data buffer) or transmitted (for example, over a computer network) and reconstructed later (possibly in a ...

What is serialization explain with example?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.

What are the types of serialization?

There are three types of serialization in . Net : Binary Serialization, SOAP Serialization and XML Serialization.


2 Answers

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.

like image 140
this. __curious_geek Avatar answered Oct 22 '22 23:10

this. __curious_geek


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)]
like image 45
Pieter Germishuys Avatar answered Oct 23 '22 00:10

Pieter Germishuys