From cdda339e9cb4187cd91c2e862738a1cef29c2cec Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 21 Jun 2021 09:56:26 -0700 Subject: [PATCH 1/6] thread-safety note --- .../system-text-json-overview.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/standard/serialization/system-text-json-overview.md b/docs/standard/serialization/system-text-json-overview.md index 8c1de2c225796..bda36e8235405 100644 --- a/docs/standard/serialization/system-text-json-overview.md +++ b/docs/standard/serialization/system-text-json-overview.md @@ -33,6 +33,29 @@ There are some limitations on what parts of the library that you can use from Vi For information about security threats that were considered when designing , and how they can be mitigated, see [`System.Text.Json` Threat Model](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/docs/ThreatModel.md). +## Thread safety + +* The `System.Text.Json` types are thread-safe, including: + +:::zone pivot="net-5-0,net-core-3-1" + +* +* +* +* +:::zone-end + +:::zone pivot="net-6-0" + +* +* +* +* +* +:::zone-end + +Use of `JsonDocument` from multiple threads requires that you call on each . + ## Additional resources * [How to use the library](system-text-json-how-to.md) From dcdf5ea46a84080441175025f4e3af6afe890113 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Tue, 22 Jun 2021 15:49:37 -0700 Subject: [PATCH 2/6] remove comment --- docs/standard/serialization/system-text-json-overview.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/standard/serialization/system-text-json-overview.md b/docs/standard/serialization/system-text-json-overview.md index bda36e8235405..c148416babaf3 100644 --- a/docs/standard/serialization/system-text-json-overview.md +++ b/docs/standard/serialization/system-text-json-overview.md @@ -54,8 +54,6 @@ For information about security threats that were considered when designing :::zone-end -Use of `JsonDocument` from multiple threads requires that you call on each . - ## Additional resources * [How to use the library](system-text-json-how-to.md) From 2cbd36f18fe6998366fc5e40cb061b0aff65c61d Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Wed, 30 Jun 2021 19:26:44 -0700 Subject: [PATCH 3/6] add note about jsonelement.clone --- .../system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md b/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md index 8f92bcecbac58..2b2241453e6e9 100644 --- a/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md +++ b/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md @@ -43,7 +43,9 @@ The preceding code: * Assumes the JSON to analyze is in a string named `jsonString`. * Calculates an average grade for objects in a `Students` array that have a `Grade` property. * Assigns a default grade of 70 for students who don't have a grade. -* Counts students by incrementing a `count` variable with each iteration. An alternative is to call , as shown in the following example: +* Creates the `JsonDocument` instance in a [`using` statement](../../csharp/language-reference/keywords/using-statement.md) because `JsonDocument` implements `IDisposable`. After a `JsonDocument` instance is disposed, you lose access to all of its `JsonElement` instances also. To retain access to a `JsonElement` instance, make a copy of it before the parent `JsonDocument` instance is disposed. To make a copy, call . + +The preceding example code counts students by incrementing a `count` variable with each iteration. An alternative is to call , as shown in the following example: :::code language="csharp" source="snippets/system-text-json-how-to/csharp/JsonDocumentDataAccess.cs" id="AverageGrades2"::: :::code language="vb" source="snippets/system-text-json-how-to/vb/JsonDocumentDataAccess.vb" id="AverageGrades2"::: From bdcaf6c3bc7b6a08dc47d2992fc3f79e259326c2 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Fri, 2 Jul 2021 09:32:57 -0700 Subject: [PATCH 4/6] link to migrate doc --- .../system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md b/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md index 2b2241453e6e9..db4d24439fb57 100644 --- a/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md +++ b/docs/standard/serialization/system-text-json-use-dom-utf8jsonreader-utf8jsonwriter.md @@ -43,7 +43,7 @@ The preceding code: * Assumes the JSON to analyze is in a string named `jsonString`. * Calculates an average grade for objects in a `Students` array that have a `Grade` property. * Assigns a default grade of 70 for students who don't have a grade. -* Creates the `JsonDocument` instance in a [`using` statement](../../csharp/language-reference/keywords/using-statement.md) because `JsonDocument` implements `IDisposable`. After a `JsonDocument` instance is disposed, you lose access to all of its `JsonElement` instances also. To retain access to a `JsonElement` instance, make a copy of it before the parent `JsonDocument` instance is disposed. To make a copy, call . +* Creates the `JsonDocument` instance in a [`using` statement](../../csharp/language-reference/keywords/using-statement.md) because `JsonDocument` implements `IDisposable`. After a `JsonDocument` instance is disposed, you lose access to all of its `JsonElement` instances also. To retain access to a `JsonElement` instance, make a copy of it before the parent `JsonDocument` instance is disposed. To make a copy, call . For more information, see [JsonDocument is IDisposable](system-text-json-migrate-from-newtonsoft-how-to.md#jsondocument-is-idisposable). The preceding example code counts students by incrementing a `count` variable with each iteration. An alternative is to call , as shown in the following example: From 1162b48ae3decea4e1928509ebcca459127675a9 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Thu, 8 Jul 2021 12:17:50 -0700 Subject: [PATCH 5/6] address build warnings --- docs/standard/serialization/system-text-json-overview.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json-overview.md b/docs/standard/serialization/system-text-json-overview.md index c148416babaf3..b87c861587af7 100644 --- a/docs/standard/serialization/system-text-json-overview.md +++ b/docs/standard/serialization/system-text-json-overview.md @@ -3,6 +3,7 @@ title: "Serialize and deserialize JSON using C# - .NET" description: This overview describes the System.Text.Json namespace functionality for serializing to and deserializing from JSON in .NET. ms.date: "01/10/2020" no-loc: [System.Text.Json, Newtonsoft.Json] +zone_pivot_groups: dotnet-version helpviewer_keywords: - "JSON serialization" - "serializing objects" @@ -51,7 +52,7 @@ For information about security threats that were considered when designing * * -* +* :::zone-end ## Additional resources From 1e2d6432e16c48ad6869863f017d99d48e8c173c Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Thu, 8 Jul 2021 12:22:49 -0700 Subject: [PATCH 6/6] address build warnings --- docs/standard/serialization/system-text-json-overview.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/standard/serialization/system-text-json-overview.md b/docs/standard/serialization/system-text-json-overview.md index b87c861587af7..1907231a47f8b 100644 --- a/docs/standard/serialization/system-text-json-overview.md +++ b/docs/standard/serialization/system-text-json-overview.md @@ -38,7 +38,7 @@ For information about security threats that were considered when designing * @@ -46,13 +46,13 @@ For information about security threats that were considered when designing :::zone-end -:::zone pivot="net-6-0" +:::zone pivot="dotnet-6-0" * * * * -* +* `JsonNode` :::zone-end ## Additional resources