We are consuming requests from upstream systems. Some time, we receive request payload with additional properties which are not defined in our entity. httpcontent.ReadAsJsonAsync fails to deserialize since property is not found in our entity. We would like to handle this case gracefully, instead of throwing deserialization exception. If there are quick workarounds to ignore additional properties passed by the up stream & deserialize only with our entity definition. We are using newtonsoft library for serialization and deserialisation.
Asked
Active
Viewed 174 times
0
-
What have you tried so far? – openshac Sep 24 '20 at 14:16
-
Does this look like what you are trying to do? https://stackoverflow.com/questions/15253875/deserialize-json-with-known-and-unknown-fields – Jim Wilcox Sep 24 '20 at 15:36
-
2By default, Newtonsoft should not throw an exception when the JSON has extra properties that the C# class does not have. If it is throwing, then check the settings. There is a [`MissingMemberHandling`](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_MissingMemberHandling.htm) setting which controls the behavior in this situation. Make sure it is set to `Ignore`. You probably have it set to `Error`. – Brian Rogers Sep 24 '20 at 16:01