I'm trying to configure JsonConvert to return an error if an attempt is made to deserialize json which includes additional properties which are not included in the C# class object. I have the following code in my Global.asax.cs > Application_Start():
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
TypeNameHandling = TypeNameHandling.Auto,
MissingMemberHandling = MissingMemberHandling.Error//,
//Error =
};
The Error property should reference an error handler for deserialization errors. What is the proper way to define/configure this type of error handler? Should the error handler be defined and implemented in it's own class or do most people tend to simply implement the method in global.asax where JsonConvert.DefaultSettings is defined.
Also, I specifically need to configure JsonConvert.DefaultSettings so it throws an error if the json contains an additional property which is not included in the C# model. Will the configuration above achieve this or do I need to take a different approach?