Table of Contents
Common serialization formats and methods
Notes
Summary
Home Backend Development C#.Net Tutorial Detailed explanation of serialization in .net

Detailed explanation of serialization in .net

Apr 03, 2017 am 11:59 AM
.net Serialization

Serialization in .net

Common serialization formats and methods

In .net, common serialization formats mainly include json, binary and xml, summarized in the following table.

Detailed explanation of serialization in .net

Back to top

Notes

About entity attribute annotation rules:

1, all in .net The [Serializable] mark should be added to the class of the entity used for serialization. If not, there will be no problem during json serialization, but an error will be reported when using BinaryFormatter for binary serialization.

2. If applied in wcf, [DataContract] tags should be added to the classes of all entities, and [DataMember] should be added to the fields.

3. When using newtonsoft.json, if [DataContract] is added to the entity class, some fields are added with [DataMember], and some fields are not added, but those that are not added should also be included during serialization. [DataMember] fields can be solved by adding [JsonObject(MemberSerialization.OptOut)] to the entity class, which means outputting all public fields.

4. When using newtonsoft.json, System.Web.UI.WebControls.ListItem cannot be serialized. The solution is to customize a class and mark it [Serializable].

Back to top

Summary

1, if it is json format, NewtonSoft.Json is the most versatile (can handle circular references), although it is not the fastest.

2. If it is in xml format, use the XmlSerializer that comes with .net.

3. If it is a binary format, use the BinaryFormatter that comes with .net. Although Protobuf is fast, it is troublesome to add the serial number.

The above is the detailed content of Detailed explanation of serialization in .net. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the employment prospects of C#? What are the employment prospects of C#? Oct 19, 2023 am 11:02 AM

Whether you are a beginner or an experienced professional, mastering C# will pave the way for your career.

Share several .NET open source AI and LLM related project frameworks Share several .NET open source AI and LLM related project frameworks May 06, 2024 pm 04:43 PM

The development of artificial intelligence (AI) technologies is in full swing today, and they have shown great potential and influence in various fields. Today Dayao will share with you 4 .NET open source AI model LLM related project frameworks, hoping to provide you with some reference. https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel is an open source software development kit (SDK) designed to integrate large language models (LLM) such as OpenAI, Azure

In Java, how can we serialize a list of objects using flexjson? In Java, how can we serialize a list of objects using flexjson? Sep 05, 2023 pm 11:09 PM

Flexjson is a lightweight library for serializing and deserializing Java objects to and from JSON format. We can serialize a list of objects using the serialize() method of the JSONSerializer class. This method performs shallow serialization on the target instance. We need to pass a list of objects of list type as a parameter to the serialize() method. Syntax publicStringserialize(Objecttarget) example importflexjson.JSONSerializer;importjava.util.*;publicclassJsonSerial

How does Java serialization affect performance? How does Java serialization affect performance? Apr 16, 2024 pm 06:36 PM

The impact of serialization on Java performance: The serialization process relies on reflection, which will significantly affect performance. Serialization requires the creation of a byte stream to store object data, resulting in memory allocation and processing costs. Serializing large objects consumes a lot of memory and time. Serialized objects increase load when transmitted over the network.

How does the C++ function library perform serialization and deserialization? How does the C++ function library perform serialization and deserialization? Apr 18, 2024 am 10:06 AM

C++ Library Serialization and Deserialization Guide Serialization: Creating an output stream and converting it to an archive format. Serialize objects into archive. Deserialization: Creates an input stream and restores it from archive format. Deserialize objects from the archive. Practical example: Serialization: Creating an output stream. Create an archive object. Create and serialize objects into the archive. Deserialization: Create an input stream. Create an archive object. Create objects and deserialize them from the archive.

PHP data processing skills: How to use the serialize and unserialize functions to implement data serialization and deserialization PHP data processing skills: How to use the serialize and unserialize functions to implement data serialization and deserialization Jul 29, 2023 am 10:49 AM

PHP data processing skills: How to use the serialize and unserialize functions to implement data serialization and deserialization Serialization and deserialization are one of the commonly used data processing skills in computer science. In PHP, we can use the serialize() and unserialize() functions to implement data serialization and deserialization operations. This article will give you a detailed introduction to how to use these two functions and provide relevant code examples. 1. What is serialization and deserialization in computer programming?

How to serialize the order of properties using Jackson library in Java? How to serialize the order of properties using Jackson library in Java? Aug 28, 2023 pm 12:45 PM

@JsonPropertyOrder is an annotation used at class level. It takes as an attribute a list of fields that defines the order in which the fields appear in the string generated by the JSON serialization of the object. Properties included in the annotation declaration can be serialized first (in the order they are defined), followed by any properties not included in the definition. Syntax public@interfaceJsonPropertyOrder Example importcom.fasterxml.jackson.core.*;importcom.fasterxml.jackson.databind.*;importcom.fasterxml.jac

Serialization and deserialization of interfaces and abstract classes in Java Serialization and deserialization of interfaces and abstract classes in Java May 02, 2024 am 08:33 AM

Interfaces cannot be serialized directly. Abstract classes can be serialized but only if they do not contain non-static, non-transient fields or override the writeObject() and readObject() methods. Specific instances can be implemented through concrete classes that implement the interface or override writeObject() and readObject. Abstract class implementation of () method.

See all articles