Skip to content

Commit f3b9e8f

Browse files
authored
[UUF] Move HTTP example out of main overview page for STJ (#44441)
1 parent 8121c2a commit f3b9e8f

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

docs/core/whats-new/dotnet-5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ For more information on project templates from the .NET CLI, see [`dotnet new`](
134134
There are new features in and for [System.Text.Json](../../standard/serialization/system-text-json/overview.md):
135135

136136
- [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)
138138
- [Allow or write numbers in quotes](../../standard/serialization/system-text-json/invalid-json.md#allow-or-write-numbers-in-quotes)
139139
- [Support immutable types and C# 9 Records](../../standard/serialization/system-text-json/immutability.md)
140140
- [Support non-public property accessors](../../standard/serialization/system-text-json/immutability.md)

docs/fundamentals/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ items:
761761
href: ../standard/serialization/system-text-json/preserve-references.md
762762
- name: Serialize polymorphic types
763763
href: ../standard/serialization/system-text-json/polymorphism.md
764+
- name: Use extension methods on HttpClient
765+
href: ../standard/serialization/system-text-json/httpclient-extensions.md
764766
- name: Read/write JSON without using JsonSerializer
765767
items:
766768
- name: Use DOM
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
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>:
14+
15+
:::code language="csharp" source="snippets/how-to-contd/csharp/HttpClientExtensionMethods.cs" highlight="23,30":::
16+
:::code language="vb" source="snippets/how-to-contd/vb/HttpClientExtensionMethods.vb":::

docs/standard/serialization/system-text-json/overview.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Serialize and deserialize JSON using C# - .NET"
2+
title: "Serialize and deserialize JSON using C#"
33
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
55
no-loc: [System.Text.Json, Newtonsoft.Json]
66
dev_langs:
77
- CSharp
@@ -13,9 +13,9 @@ helpviewer_keywords:
1313
- "objects, serializing"
1414
---
1515

16-
# JSON serialization and deserialization (marshalling and unmarshalling) in .NET - overview
16+
# JSON serialization and deserialization in .NET - overview
1717

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.
1919

2020
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.
2121

@@ -31,15 +31,13 @@ For framework versions earlier than .NET Core 3.0, install the [System.Text.Json
3131

3232
* .NET Standard 2.0 and later
3333
* .NET Framework 4.6.2 and later
34-
* .NET Core 2.1 and later
35-
* .NET 5 and later
34+
* .NET 8 and later
3635

3736
## Namespaces and APIs
3837

3938
* The <xref:System.Text.Json> namespace contains all the entry points and the main types.
4039
* 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).
4341

4442
> [!IMPORTANT]
4543
>
@@ -48,17 +46,6 @@ The code examples shown in this article require `using` directives for one or bo
4846
> * Attributes from the <xref:System.Runtime.Serialization> namespace.
4947
> * 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).
5048
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>:
56-
57-
:::code language="csharp" source="snippets/how-to-contd/csharp/HttpClientExtensionMethods.cs" highlight="23,30":::
58-
:::code language="vb" source="snippets/how-to-contd/vb/HttpClientExtensionMethods.vb" :::
59-
60-
There are also extension methods for System.Text.Json on [HttpContent](xref:System.Net.Http.Json.HttpContentJsonExtensions).
61-
6249
## Reflection vs. source generation
6350

6451
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

Comments
 (0)