-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Jsonpartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated
Milestone
Description
Background
We recently got feedback from the Azure team that the built-in JsonSerializerOptions defaults are not fit for purpose from the perspective of their recommended best practices. More specifically:
- All defaults serialize enums as strings
- The
JsonSerializerDefaults.Websetting uses case insensitive property binding - The
JsonSerializerDefaults.Websetting allows deserializing numbers from strings. - All defaults tolerate unmapped JSON members
- All configurations tolerate duplicate JSON properties
This issue proposes that we expose a new JsonSerializerDefaults value (let's call it JsonSerializerDefaults.Strict_V1 for now) that enables the following settings:
Applies theJsonNamingPolicy.CamelCaseproperty naming policyApplies the.JsonStringEnumConverterfor all enum types withallowIntegerValuesset to false- Applies the
JsonUnmappedMemberHandling.Disallowpolicy - Disallows duplicate JSON properties.
- Preserves case sensitive property binding
- Enables both
RespectNullableAnnotationsandRespectRequiredConstructorParameterssettings.
API proposal
namespace System.Text.Json
public enum JsonSerializerDefaults
{
General = 0, // The default configuration set
Web = 1, // The default configuration set used by aspnetcore
+ Strict_V1 = 2 // The proposed configuration set
}
public partial class JsonSerializerOptions
{
public static JsonSerializerOptions Default { get; }
public static JsonSerializerOptions Web { get; }
+ public static JsonSerializerOptions Strict_V1 { get; }
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Jsonpartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated