serialization elaboration in. Net

Source: Internet
Author: User

Serialization in. Net

Common serialization formats and methods

In. NET, the common serialization format is mainly JSON, binary, and XML, summarized in the following table.

Back to Top

Precautions

About entity attribute labeling rules:

The [Serializable] tag should be added to the class of all entities used for serialization in 1,.net, and if not added, there is no problem with JSON serialization, but the error occurs when using BinaryFormatter for binary serialization.

2, if applied in WCF, the [DataContract] tag should also be added to the class on all entities, with [DataMember] on the field.

3, when using Newtonsoft.json, if the entity class added [DataContract], some fields added [DataMember], and some fields are not added, but also to serialize the time to include those that do not add [DataMember] field, You can add [Jsonobject (Memberserialization.optout)] on the entity class to resolve it, representing the output of all public fields.

4, when using Newtonsoft.json, System.Web.UI.WebControls.ListItem cannot be serialized, the workaround is to customize a class and tag [Serializable].

Back to Top

Summarize

1, if it is in JSON format, Newtonsoft.json is the most common (can handle circular reference), although it is not the fastest.

2, if it is in XML format, use the. NET XmlSerializer.

3, if it is a binary format, use the. NET BinaryFormatter, although the protobuf speed, but to add serial number is very troublesome.

Related Article

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.