Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/core/whats-new/dotnet-8.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ For example, consider the following code that deserializes into a `CustomerInfo`
using System.Text.Json;

CustomerInfo customer =
JsonSerializer.Deserialize<CustomerInfo>("""{"Name":"John Doe","Company":{"Name":"Contoso"}}""")!;
JsonSerializer.Deserialize<CustomerInfo>("""{"Names":["John Doe"],"Company":{"Name":"Contoso"}}""")!;

Console.WriteLine(JsonSerializer.Serialize(customer));

Expand All @@ -187,21 +187,21 @@ class CompanyInfo
class CustomerInfo
{
// Both of these properties are read-only.
public string Name { get; } = "Anonymous";
public List<string> Names { get; } = new();
public CompanyInfo Company { get; } = new() { Name = "N/A", PhoneNumber = "N/A" };
}
```

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
{"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
Expand Down