开发者

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

开发者 https://www.devze.com 2023-01-03 06:28 出处:网络
This question already has answers here: 开发者_StackOverflow中文版 What is Serialization? (16 answers)
This question already has answers here: 开发者_StackOverflow中文版 What is Serialization? (16 answers) Closed 2 years ago.

What is the meaning of serialization concept in programming languages?

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


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.


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)]


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消