diff --git a/docs/standard/datetime/how-to-use-dateonly-timeonly.md b/docs/standard/datetime/how-to-use-dateonly-timeonly.md index e4ebb68226a66..71954d5d41c04 100644 --- a/docs/standard/datetime/how-to-use-dateonly-timeonly.md +++ b/docs/standard/datetime/how-to-use-dateonly-timeonly.md @@ -127,7 +127,26 @@ Because `TimeOnly` only represents a 24-hour period, it rolls over forwards or b ### Serialize DateOnly and TimeOnly types -[!INCLUDE [dateonly-and-timeonly-serialization](includes/dateonly-and-timeonly-serialization.md)] + + +Starting in .NET 7, `System.Text.Json` supports serializing and deserializing and types. Consider the following object: + +:::code source="./snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="appointment"::: +:::code source="./snippets/how-to-use-dateonly-timeonly/vb/Program.vb" id="appointment"::: + +The following example serializes an `Appointment` object, displays the resulting JSON, and then deserializes it back into a new instance of the `Appointment` type. Finally, the original and newly deserialized instances are compared for equality and the results are written to the console: + +:::code source="./snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="serialization"::: +:::code source="./snippets/how-to-use-dateonly-timeonly/vb/Program.vb" id="serialization"::: + +In the preceding code: + +- An `Appointment` object is instantiated and assigned to the `appointment` variable. +- The `appointment` instance is serialized to JSON using . +- The resulting JSON is written to the console. +- The JSON is deserialized back into a new instance of the `Appointment` type using . +- The original and newly deserialized instances are compared for equality. +- The result of the comparison is written to the console. For more information, see [How to serialize and deserialize JSON in .NET](../serialization/system-text-json/how-to.md). diff --git a/docs/standard/datetime/includes/dateonly-and-timeonly-serialization-cs.md b/docs/standard/datetime/includes/dateonly-and-timeonly-serialization-cs.md deleted file mode 100644 index 68d8b78560323..0000000000000 --- a/docs/standard/datetime/includes/dateonly-and-timeonly-serialization-cs.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -ms.date: 01/11/2023 -ms.topic: include ---- - -With .NET 7+, `System.Text.Json` supports serializing and deserializing and types. Consider the following object: - -:::code source="../snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="appointment"::: - -The following example serializes an `Appointment` object, displays the resulting JSON, and then deserializes it back into a new instance of the `Appointment` type. Finally, the original and newly deserialized instances are compared for equality and the results are written to the console: - -:::code source="../snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="serialization"::: - -In the preceding code: - -- An `Appointment` object is instantiated and assigned to the `appointment` variable. -- The `appointment` instance is serialized to JSON using . -- The resulting JSON is written to the console. -- The JSON is deserialized back into a new instance of the `Appointment` type using . -- The original and newly deserialized instances are compared for equality. -- The result of the comparison is written to the console. diff --git a/docs/standard/datetime/includes/dateonly-and-timeonly-serialization.md b/docs/standard/datetime/includes/dateonly-and-timeonly-serialization.md deleted file mode 100644 index 992c3e32acd7e..0000000000000 --- a/docs/standard/datetime/includes/dateonly-and-timeonly-serialization.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -ms.date: 01/11/2023 -ms.topic: include ---- - -With .NET 7+, `System.Text.Json` supports serializing and deserializing and types. Consider the following object: - -:::code source="../snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="appointment"::: -:::code source="../snippets/how-to-use-dateonly-timeonly/vb/Program.vb" id="appointment"::: - -The following example serializes an `Appointment` object, displays the resulting JSON, and then deserializes it back into a new instance of the `Appointment` type. Finally, the original and newly deserialized instances are compared for equality and the results are written to the console: - -:::code source="../snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="serialization"::: -:::code source="../snippets/how-to-use-dateonly-timeonly/vb/Program.vb" id="serialization"::: - -In the preceding code: - -- An `Appointment` object is instantiated and assigned to the `appointment` variable. -- The `appointment` instance is serialized to JSON using . -- The resulting JSON is written to the console. -- The JSON is deserialized back into a new instance of the `Appointment` type using . -- The original and newly deserialized instances are compared for equality. -- The result of the comparison is written to the console. diff --git a/docs/standard/datetime/system-text-json-support.md b/docs/standard/datetime/system-text-json-support.md index e995755d37193..8d67d2948aaf5 100644 --- a/docs/standard/datetime/system-text-json-support.md +++ b/docs/standard/datetime/system-text-json-support.md @@ -59,7 +59,24 @@ If you attempt to read non-compliant formats with and types. Consider the following object: + + + +:::code source="snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="appointment"::: + +The following example serializes an `Appointment` object, displays the resulting JSON, and then deserializes it back into a new instance of the `Appointment` type. Finally, the original and newly deserialized instances are compared for equality and the results are written to the console: + +:::code source="snippets/how-to-use-dateonly-timeonly/csharp/Program.cs" id="serialization"::: + +In the preceding code: + +- An `Appointment` object is instantiated and assigned to the `appointment` variable. +- The `appointment` instance is serialized to JSON using . +- The resulting JSON is written to the console. +- The JSON is deserialized back into a new instance of the `Appointment` type using . +- The original and newly deserialized instances are compared for equality. +- The result of the comparison is written to the console. ## Custom support for and