Skip to content

Commit 5111056

Browse files
authored
Note no partial reads (#21991)
1 parent 0ad2d6c commit 5111056

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/standard/serialization/system-text-json-converters-how-to.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "How to write custom converters for JSON serialization - .NET"
33
description: "Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace."
4-
ms.date: 12/09/2020
4+
ms.date: 12/14/2020
55
no-loc: [System.Text.Json, Newtonsoft.Json]
66
zone_pivot_groups: dotnet-version
77
helpviewer_keywords:
@@ -77,7 +77,7 @@ The preceding code is the same as what is shown in the [Support Dictionary with
7777
The following steps explain how to create a converter by following the basic pattern:
7878

7979
* Create a class that derives from <xref:System.Text.Json.Serialization.JsonConverter%601> where `T` is the type to be serialized and deserialized.
80-
* Override the `Read` method to deserialize the incoming JSON and convert it to type `T`. Use the <xref:System.Text.Json.Utf8JsonReader> that is passed to the method to read the JSON.
80+
* Override the `Read` method to deserialize the incoming JSON and convert it to type `T`. Use the <xref:System.Text.Json.Utf8JsonReader> that is passed to the method to read the JSON. You don't have to worry about handling partial data, as the serializer passes all the data for the current JSON scope. So it isn't necessary to call <xref:System.Text.Json.Utf8JsonReader.Skip%2A> or <xref:System.Text.Json.Utf8JsonReader.TrySkip%2A> or to validate that <xref:System.Text.Json.Utf8JsonReader.Read%2A> returns `true`.
8181
* Override the `Write` method to serialize the incoming object of type `T`. Use the <xref:System.Text.Json.Utf8JsonWriter> that is passed to the method to write the JSON.
8282
* Override the `CanConvert` method only if necessary. The default implementation returns `true` when the type to convert is of type `T`. Therefore, converters that support only type `T` don't need to override this method. For an example of a converter that does need to override this method, see the [polymorphic deserialization](#support-polymorphic-deserialization) section later in this article.
8383

@@ -370,7 +370,7 @@ This null-handling behavior is primarily to optimize performance by skipping an
370370
::: zone pivot="dotnet-5-0"
371371
To enable a custom converter to handle `null` for a reference or value type, override <xref:System.Text.Json.Serialization.JsonConverter%601.HandleNull%2A?displayProperty=nameWithType> to return `true`, as shown in the following example:
372372

373-
:::code language="csharp" source="snippets/system-text-json-how-to-5-0/csharp/CustomConverterHandleNull.cs" highlight="19":::
373+
:::code language="csharp" source="snippets/system-text-json-how-to-5-0/csharp/CustomConverterHandleNull.cs" highlight="18":::
374374
::: zone-end
375375

376376
## Other custom converter samples

0 commit comments

Comments
 (0)