I am using JsonConvert.DeserializeObject
to deserialize some objects. There is a possibility that the properties in the json file may not be present in the corresponding definition. When this happens, I want to essentially ignore the field and continue deserializing, but print a warning in the console that the field was missing.
The documentation for DeserializeObject
shows that an additional JsonSerializerSettings
argument can be given, and that contains a MissingMemberHandling setting. However, the two options available for that setting are Ignore
and Error
. The former silently ignores missing fields and continues, and the latter stops the deserialization and throws an error. I seem to need something in between these two.
I have seen the similar question here Detect if deserialized object is missing a field with the JsonConvert class in Json.NET. However, in this question, the original post wants the deserializer to throw an error and stop deserializing. I would like it to continue, but just inform the user of the field mismatch. Is there a way to do this?