Newtonsoft still creates object even with Handled flag set to true

时间:2019-05-31 11:41:52

标签: c# json.net

Basically, what I want is when there is deserialization error simply to log the error, skip this object and proceed. I've set

return JsonConvert.DeserializeObject<IList<T>>(json, new JsonSerializerSettings
        {
            Error = (sender, args) => { args.ErrorContext.Handled = true; },
            NullValueHandling = NullValueHandling.Ignore
        });

I get the error and can be logged, but it still creates object with default value for the property where it failed to deserialize. I just want objects with deserialization error to not be part of the list I'm returning. Is there a way?

0 个答案:

没有答案