Common Object serialization and deserialization Technologies

Source: Internet
Author: User
Tags object serialization

Summary: This article briefly describes several common object serialization and deserialization technologies, and analyzes their advantages and disadvantages. I hope to learn from your programming.

Note: Object serialization and deserialization refer to the serialization and deserialization of object information in a narrow sense, excluding the serialization and deserialization of large data volumes using database technology.

The emergence of Object serialization and deserialization technology from computers is an important technology. After continuous evolution, three common types of technology have been produced.

Key Information Restoration

Honestly, I haven't come up with a proper name for a long time, such as INI, registry, or some XML configurations (such. NET 1.0 config files) can be summarized into this type, their characteristics are:

-There is no one-to-one correspondence between information configuration items and objects;

-The reading and saving of information must be explained by programming;

-Only the key information of an object is saved and restored.

For example, the registry contains information about the size of a form.ProgramYou need to read this information at startup and assign this information to the form object. When the window is closed, retrieve the window size and write it to the Registry. TypicalCode:

This. size = stringtosize (config. item ["formsize"]);

It can be seen that this method is very elementary for serialization and deserialization. When there are not many pieces of information to store, it is very simple to implement, but it will be a nightmare when the configuration changes a lot.

Entity serialization and deserialization Technology

I think this method is a standard serialization and deserialization technology .. Net binary serialization, XML serialization technology, and the new configuration system of. NET 2.0. Their features are:

-There are obviously entity objects designed according to certain specifications, and the general engine is used for serialization and deserialization;

-Information is summarized into a whole entity;

-High information restoration.

For example, you can mark the serialization flag on a class and then use the binary serialization engine for serialization or deserialization. The typical entity code is:

Sealed class formsettings: applicationsettingsbase

{

[Userscopedsettingattribute ()]

Public String formtext

{

Get {return (string) This ["formtext"];}

Set {This ["formtext"] = value ;}

}

This method can basically adapt to the vast majority of tasks, but it also has its disadvantages: the configuration information is interpreted, so it is theoretically a finite set. How much do you consider, you can only do this. As a result, new technologies have been paid more and more attention in recent years:

Code serialization and deserialization

This is a more complex implementation technology based on the previous method.Source codeDescribe the configuration information. Compile or explain the source code when deserialization is required. Generally, an object is restored. In fact, you are using this technology every day. This is the Form Designer of Visual Studio. NET. He shows:

-The code is usually used to search for attributes to create serialization. Of course, this technology is dozens of times more complex than entity serialization;

-The serialization information can contain appropriate logic;

-Information restoration is very high.

At present, I have seen that the latest report system of developer express uses the same technology to serialize and deserialize report information (internal engines are open in MS ). I think this technology has a very promising prospect for high-end applications, and its high threshold makes it impossible for him to be widely used in general applications.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.