2

How to I get Json.NET to throw an exception when JSON doesn't contain a property, which is a member of the object (during deserialization)?

ie, i'm looking for the inverse functionality to JsonSerializerSettings.MissingMemberHandling.

Edit / Solution from DBC: use Json.NET require all properties on deserialization Json.NET require all properties on deserialization

k c
  • 88
  • 8
  • 2
    Are you looking for [Json.NET require all properties on deserialization](https://stackoverflow.com/q/29655502) and/or [Deserializing with Json.NET: Requiring a property/key to be present](https://stackoverflow.com/q/16292009)? – dbc Oct 29 '18 at 13:29
  • Thanks dbc - RequireObjectPropertiesContractResolver is the solution! Perhaps this feature should added as a built in JsonSerializer Property? – k c Oct 29 '18 at 14:12
  • Glad to help. As for making it built-in, I've been thinking that Json.NET needs an easier way to plug in standard behaviors into a contract resolver beyond just subclassing. Splitting out the [`NamingStrategy`](https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_Serialization_DefaultContractResolver_NamingStrategy.htm) was a good first step. – dbc Oct 29 '18 at 14:18

0 Answers0