How to ignore an error using Json.NET without damaging what has already been read

Asked

Viewed 60 times

1

Is there any way to continue the "de-realization" of an object, using Json.NET, even when a property is corrupted and without damaging what has already been "read"?

1 answer

1


Yes, it is possible by using a JsonConverter. The class JsonConverter converts an object to JSON and vice versa, but this process can be customized if you create a class that derives from it and overwrite the methods JsonConverter.ReadJson and/or JsonConverter.WriteJson.

The official Json.NET documentation has a very simple example of how to custom Jsonconverter can be implemented. Here the example link.

Note that you can also specify a JsonConverter to be used as a standard during the process of "serialization" and "deserialization" of an object through the attribute JsonConverterAttribute, this can be useful to accelerate development.

I also recommend that you take a look at the example of answer to that question in the Stack Overflow (English) Using Json.NET converters to deserialize properties. It can be very useful to you as a starter to develop your custom Jsonconverter.

  • I think it lacked to detail better, in fact I do not know the object that will be deserialized, will be dynamic. Before I delve into Jsonconvert, you could tell if this is possible with it?

  • Yes, it’s entirely possible, Jsonconveter allows you to have complete control over serialization and deserialization, I recommended it precisely because Oce said that a property could be corrupted, so you could treat this property during the process.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.