JsonApi Ignoring MissingMemberHandling Serializer Setting
Opened this issue · 1 comments
Hi,
I am setting the MissingMemberHandling to Error in the JsonApiSerializerSettings so that if there are any unknown/non-declared property in the json, I get deserialization error. However the setting is getting ignored.
`var json = "{ \"data\": { \"id\": \"1\", \"type\" : \"product\", \"attributes\" : { \"name\": \"name\", \"summary\": \"summary\" } }}";
var jsonApiSerializerSettings = new JsonApiSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Error,
};
var product = JsonConvert.DeserializeObject<Product>(json, jsonApiSerializerSettings);`
Whereas when using the same setting with JsonSerializerSettings, the error do get generated.
`var json = "{ \"id\": \"1\", \"type\" : \"product\", \"name\": \"name\", \"summary\": \"summary\" }";
var jsonSerializerSettings = new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Error,
};
var product = JsonConvert.DeserializeObject<Product>(json, jsonSerializerSettings);`
Below error gets generated at the deserialization:
Could not find member '{property}' on object of type '{type}'
I have also created a sample application for reference:
https://github.com/ShawetaKumar/JsonDeserialization
I have also added a failing test to the code to verify the same
When_passed_unknown_property_should_throw_exception_when_missing_member_handling_set_to_error
https://github.com/ShawetaKumar/JsonApiSerializer/blob/bug/missing-member-handling/tests/JsonApiSerializer.Test/DeserializationTests/DeserializationExceptionTests.cs
Support for MissingMemebrHandling.Error is required to implement this particular part of the JSON:API spec where you want the API to reject unsupported updates which contain attributes which are not recognised:
A server MUST return 403 Forbidden in response to an unsupported request to update a resource or relationship.