From 5791685223996e73045438fe3f815850c24c818e Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Thu, 2 Dec 2021 14:53:47 -0800 Subject: [PATCH 1/2] Add note about order of JSON objects --- .../serialization/system-text-json-converters-how-to.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json-converters-how-to.md b/docs/standard/serialization/system-text-json-converters-how-to.md index 8e33e3f82bebe..a47cbee7b0f50 100644 --- a/docs/standard/serialization/system-text-json-converters-how-to.md +++ b/docs/standard/serialization/system-text-json-converters-how-to.md @@ -322,7 +322,7 @@ Built-in features provide a limited range of [polymorphic serialization](system- Suppose, for example, you have a `Person` abstract base class, with `Employee` and `Customer` derived classes. Polymorphic deserialization means that at design time you can specify `Person` as the deserialization target, and `Customer` and `Employee` objects in the JSON are correctly deserialized at run time. During deserialization, you have to find clues that identify the required type in the JSON. The kinds of clues available vary with each scenario. For example, a discriminator property might be available or you might have to rely on the presence or absence of a particular property. The current release of `System.Text.Json` doesn't provide attributes to specify how to handle polymorphic deserialization scenarios, so custom converters are required. -The following code shows a base class, two derived classes, and a custom converter for them. The converter uses a discriminator property to do polymorphic deserialization. The type discriminator isn't in the class definitions but is created during serialization and is read during deserialization. +The following code shows a base class, two derived classes, and a custom converter for them. The converter uses a discriminator property to do polymorphic deserialization. The type discriminator isn't in the class definitions but is created during serialization and is read during deserialization. The example code requires JSON object name/value pairs to stay in order, which is not a standard requirement of JSON. :::code language="csharp" source="snippets/system-text-json-how-to/csharp/Person.cs" id="Person"::: From 0b2c21f3dfd3fe15d5bf5cd33d9666657ef250fe Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Fri, 3 Dec 2021 08:12:51 -0800 Subject: [PATCH 2/2] Update docs/standard/serialization/system-text-json-converters-how-to.md Co-authored-by: David Pine --- .../serialization/system-text-json-converters-how-to.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/standard/serialization/system-text-json-converters-how-to.md b/docs/standard/serialization/system-text-json-converters-how-to.md index a47cbee7b0f50..eea0ec5e9e143 100644 --- a/docs/standard/serialization/system-text-json-converters-how-to.md +++ b/docs/standard/serialization/system-text-json-converters-how-to.md @@ -322,7 +322,10 @@ Built-in features provide a limited range of [polymorphic serialization](system- Suppose, for example, you have a `Person` abstract base class, with `Employee` and `Customer` derived classes. Polymorphic deserialization means that at design time you can specify `Person` as the deserialization target, and `Customer` and `Employee` objects in the JSON are correctly deserialized at run time. During deserialization, you have to find clues that identify the required type in the JSON. The kinds of clues available vary with each scenario. For example, a discriminator property might be available or you might have to rely on the presence or absence of a particular property. The current release of `System.Text.Json` doesn't provide attributes to specify how to handle polymorphic deserialization scenarios, so custom converters are required. -The following code shows a base class, two derived classes, and a custom converter for them. The converter uses a discriminator property to do polymorphic deserialization. The type discriminator isn't in the class definitions but is created during serialization and is read during deserialization. The example code requires JSON object name/value pairs to stay in order, which is not a standard requirement of JSON. +The following code shows a base class, two derived classes, and a custom converter for them. The converter uses a discriminator property to do polymorphic deserialization. The type discriminator isn't in the class definitions but is created during serialization and is read during deserialization. + +> [!IMPORTANT] +> The example code requires JSON object name/value pairs to stay in order, which is not a standard requirement of JSON. :::code language="csharp" source="snippets/system-text-json-how-to/csharp/Person.cs" id="Person":::