I am using the Newtonsoft JSON library to deserialize a response from a web service. The problem is that some of the fields contain values which are not valid. For example, one field on one record contained a "T" for a field that is supposed to be numeric. What I would like to do is to have values for fields that are invalid be null, or some other default value. All of my properties are defined as nullable, so it is fine if they default to null.
Is there a way to do this? I have tried creating custom JsonConverters, but I would prefer to not have to define a JsonConverter for each type. If possible, I would like to, for all fields, set them null if the value for that property is not valid (like a "T" for a numeric type).
I have looked at the OnError event handler, but that seems to discard a whole record on error. I do not want to discard any records. I would just like for the value of invalid properties to be null.
Is this possible? I have looked a lot for answers and I did not find another question that was trying to do this, but please let me know if I overlooked an existing question.
Thank you for your help.
objectthen doing the checking post parsing. Or possibly something like this Let me know if I'm mistaken in your intent.