System.Text.Json
Any JSON properties that aren’t represented in your class are ignored by default. Also, if any properties on the type are required but not present in the JSON payload, deserialization will fail.
Starting in .NET 7, you can mark certain properties to signify that they must be present in the JSON payload for deserialization to succeed. If one or more of these required properties is not present, the JsonSerializer.Deserialize methods throw a JsonException.There are three ways to mark a property or field as required for JSON deserialization:
- By adding the required modifier, which is new in C# 11.
- By annotating it with JsonRequiredAttribute, which is new in .NET 7.
- By modifying the JsonPropertyInfo.IsRequired property of the contract model, which is new in .NET 7.
Deserialization behavior: https://arc.net/l/quote/rlyayhmm
- By default, property name matching is case-sensitive.
- Non-public constructors are ignored by the serializer. ??
- …
When you use System.Text.Json indirectly in an ASP.NET Core app, some default behaviors are different. For more information, see Web defaults for JsonSerializerOptions.
The following options have different defaults for web apps: