You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/whats-new/dotnet-5.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,7 +134,7 @@ For more information on project templates from the .NET CLI, see [`dotnet new`](
134
134
There are new features in and for [System.Text.Json](../../standard/serialization/system-text-json/overview.md):
135
135
136
136
-[Preserve references and handle circular references](../../standard/serialization/system-text-json/preserve-references.md)
137
-
-[HttpClient and HttpContent extension methods](../../standard/serialization/system-text-json/overview.md#httpclient-and-httpcontent-extension-methods)
137
+
-[Serialization extension methods on HttpClient](../../standard/serialization/system-text-json/httpclient-extensions.md)
138
138
-[Allow or write numbers in quotes](../../standard/serialization/system-text-json/invalid-json.md#allow-or-write-numbers-in-quotes)
139
139
-[Support immutable types and C# 9 Records](../../standard/serialization/system-text-json/immutability.md)
title: "Serialization extension methods on HttpClient"
3
+
description: Learn how to serialize and deserialize JSON payloads from the network in a single line of code using extension methods on HttpClient and HttpContent.
4
+
ms.date: 01/19/2025
5
+
dev_langs:
6
+
- CSharp
7
+
- VB
8
+
---
9
+
# Serialization extension methods on HttpClient
10
+
11
+
Serializing and deserializing JSON payloads from the network are common operations. Extension methods on [HttpClient](xref:System.Net.Http.Json.HttpClientJsonExtensions) and [HttpContent](xref:System.Net.Http.Json.HttpContentJsonExtensions) let you do these operations in a single line of code. These extension methods use [web defaults for JsonSerializerOptions](configure-options.md#web-defaults-for-jsonserializeroptions).
12
+
13
+
The following example illustrates use of <xref:System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync%2A?displayProperty=nameWithType> and <xref:System.Net.Http.Json.HttpClientJsonExtensions.PostAsJsonAsync%2A?displayProperty=nameWithType>:
Copy file name to clipboardExpand all lines: docs/standard/serialization/system-text-json/overview.md
+6-19Lines changed: 6 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: "Serialize and deserialize JSON using C# - .NET"
2
+
title: "Serialize and deserialize JSON using C#"
3
3
description: This overview describes the System.Text.Json namespace functionality for serializing to and deserializing from JSON in .NET.
4
-
ms.date: 10/18/2021
4
+
ms.date: 01/19/2025
5
5
no-loc: [System.Text.Json, Newtonsoft.Json]
6
6
dev_langs:
7
7
- CSharp
@@ -13,9 +13,9 @@ helpviewer_keywords:
13
13
- "objects, serializing"
14
14
---
15
15
16
-
# JSON serialization and deserialization (marshalling and unmarshalling) in .NET - overview
16
+
# JSON serialization and deserialization in .NET - overview
17
17
18
-
The <xref:System.Text.Json> namespace provides functionality for serializing to and deserializing from JavaScript Object Notation (JSON). *Serialization* is the process of converting the state of an object, that is, the values of its properties, into a form that can be stored or transmitted. The serialized form doesn't include any information about an object's associated methods. *Deserialization* reconstructs an object from the serialized form.
18
+
The <xref:System.Text.Json> namespace provides functionality for serializing to and deserializing from (or marshalling and unmarshalling) JavaScript Object Notation (JSON). *Serialization* is the process of converting the state of an object, that is, the values of its properties, into a form that can be stored or transmitted. The serialized form doesn't include any information about an object's associated methods. *Deserialization* reconstructs an object from the serialized form.
19
19
20
20
The `System.Text.Json` library design emphasizes high performance and low memory allocation over an extensive feature set. Built-in UTF-8 support optimizes the process of reading and writing JSON text encoded as UTF-8, which is the most prevalent encoding for data on the web and files on disk.
21
21
@@ -31,15 +31,13 @@ For framework versions earlier than .NET Core 3.0, install the [System.Text.Json
31
31
32
32
* .NET Standard 2.0 and later
33
33
* .NET Framework 4.6.2 and later
34
-
* .NET Core 2.1 and later
35
-
* .NET 5 and later
34
+
* .NET 8 and later
36
35
37
36
## Namespaces and APIs
38
37
39
38
* The <xref:System.Text.Json> namespace contains all the entry points and the main types.
40
39
* The <xref:System.Text.Json.Serialization> namespace contains attributes and APIs for advanced scenarios and customization specific to serialization and deserialization.
41
-
42
-
The code examples shown in this article require `using` directives for one or both of these namespaces.
40
+
* The <xref:System.Net.Http.Json> namespace contains extension methods for [serializing and deserializing JSON payloads from the network](httpclient-extensions.md).
43
41
44
42
> [!IMPORTANT]
45
43
>
@@ -48,17 +46,6 @@ The code examples shown in this article require `using` directives for one or bo
48
46
> * Attributes from the <xref:System.Runtime.Serialization> namespace.
49
47
> * The <xref:System.SerializableAttribute?displayProperty=fullName> attribute and the <xref:System.Runtime.Serialization.ISerializable> interface. These types are used only for [Binary and XML serialization](/previous-versions/dotnet/fundamentals/serialization/binary/binary-serialization).
50
48
51
-
### HttpClient and HttpContent extension methods
52
-
53
-
Serializing and deserializing JSON payloads from the network are common operations. Extension methods on [HttpClient](xref:System.Net.Http.Json.HttpClientJsonExtensions) and [HttpContent](xref:System.Net.Http.Json.HttpContentJsonExtensions) let you do these operations in a single line of code. These extension methods use [web defaults for JsonSerializerOptions](configure-options.md#web-defaults-for-jsonserializeroptions).
54
-
55
-
The following example illustrates use of <xref:System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync%2A?displayProperty=nameWithType> and <xref:System.Net.Http.Json.HttpClientJsonExtensions.PostAsJsonAsync%2A?displayProperty=nameWithType>:
There are also extension methods for System.Text.Json on [HttpContent](xref:System.Net.Http.Json.HttpContentJsonExtensions).
61
-
62
49
## Reflection vs. source generation
63
50
64
51
By default, `System.Text.Json` gathers the metadata it needs to access properties of objects for serialization and deserialization *at run time* using [reflection](/dotnet/csharp/advanced-topics/reflection-and-attributes/). As an alternative, `System.Text.Json` can use the C# [source generation](../../../csharp/roslyn-sdk/index.md#source-generators) feature to improve performance, reduce private memory usage, and facilitate [assembly trimming](../../../core/deploying/trimming/trim-self-contained.md), which reduces app size.
0 commit comments