From ae16c34fe770450e9bc493f3aafa8078af04ea38 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Sun, 1 Oct 2023 10:48:07 +0100 Subject: [PATCH 1/2] Fix dotnet-8.md code sample --- docs/core/whats-new/dotnet-8.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/core/whats-new/dotnet-8.md b/docs/core/whats-new/dotnet-8.md index f19148498a086..e63f6a7bc5ee7 100644 --- a/docs/core/whats-new/dotnet-8.md +++ b/docs/core/whats-new/dotnet-8.md @@ -173,7 +173,7 @@ For example, consider the following code that deserializes into a `CustomerInfo` using System.Text.Json; CustomerInfo customer = - JsonSerializer.Deserialize("""{"Name":"John Doe","Company":{"Name":"Contoso"}}""")!; + JsonSerializer.Deserialize("""{"Names":["John Doe"],"Company":{"Name":"Contoso"}}""")!; Console.WriteLine(JsonSerializer.Serialize(customer)); @@ -187,7 +187,7 @@ class CompanyInfo class CustomerInfo { // Both of these properties are read-only. - public string Name { get; } = "Anonymous"; + public List Names { get; } = new(); public CompanyInfo Company { get; } = new() { Name = "N/A", PhoneNumber = "N/A" }; } ``` @@ -195,13 +195,13 @@ class CustomerInfo Prior to .NET 8, the input values were ignored and the `Name` and `Company` properties retained their default values. ```output -{"Name":"Anonymous","Company":{"Name":"N/A","PhoneNumber":"N/A"}} +{"Names":[],"Company":{"Name":"N/A","PhoneNumber":"N/A"}} ``` Now, the input values are used to populate the read-only properties during deserialization. ```output -{"Name":"John Doe","Company":{"Name":"Contoso","PhoneNumber":null}} +{"Names":["John Doe"],"Company":{"Name":"Contoso","PhoneNumber":null}} ``` #### Disable reflection-based default From 9b298f80bc6ca2e963827c7d3ff0e8d0c9f2252c Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Sun, 1 Oct 2023 10:49:06 +0100 Subject: [PATCH 2/2] Update docs/core/whats-new/dotnet-8.md --- docs/core/whats-new/dotnet-8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/whats-new/dotnet-8.md b/docs/core/whats-new/dotnet-8.md index e63f6a7bc5ee7..938fef7ce2420 100644 --- a/docs/core/whats-new/dotnet-8.md +++ b/docs/core/whats-new/dotnet-8.md @@ -192,7 +192,7 @@ class CustomerInfo } ``` -Prior to .NET 8, the input values were ignored and the `Name` and `Company` properties retained their default values. +Prior to .NET 8, the input values were ignored and the `Names` and `Company` properties retained their default values. ```output {"Names":[],"Company":{"Name":"N/A","PhoneNumber":"N/A"}}