-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json
Milestone
Description
We would love to migrate our ASP.NET Core 3 application from using Newtonsoft.Json to System.Text.Json. However, the lack of support/workaround for MissingMemberHandling is a showstopper, because we need a robust way to detect and report deficient [FromBody] model binding. Without this feature, mistakes in the input JSON document can go undetected, and that is not acceptable.
Is adding MissingMemberHandling something that is planned for System.Text.Json?
EDIT @eiriktsarpalis: API proposal & usage examples added
API Proposal
namespace System.Text.Json;
public enum JsonMissingMemberHandling { Ignore = 0, Error = 1 }
public partial class JsonSerializerOptions
{
// Global configuration
public JsonMissingMemberHandling MissingMemberHandling { get; set; } = JsonMissingMemberHandling.Ignore;
}namespace System.Text.Json.Serialization;
// Per-type attribute-level configuration
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, AllowMultiple=false, Inherited=false)]
public class JsonMissingMemberHandlingAttribute : JsonAttribute
{
public JsonMissingMemberHandlingAttribute(JsonMissingMemberHandling missingMemberHandling);
public JsonMissingMemberHandlingAttribute MissingMemberHandling { get; }
}
namespace System.Text.Json.Serialization.Metadata;
public partial class JsonTypeInfo
{
// Per-type configuration via contract customization.
public JsonMissingMemberHandling MissingMemberHandling { get; set; } = JsonMissingMemberHandling.Ignore;
}API Usage
JsonSerializer.Deserialize<MyPoco>("""{ "jsonPropertyNotBindingToPocoProperty" : null}"""); // JsonException: member not found
[JsonMissingMemberHandling(JsonMissingMember.Error)]
public class MyPoco { }vslee, ryan-morris, danjagnow, hennys, ben-marsh and 36 more
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.Json