JSON.NET and managing type information provided in the output stream

We want to use JSON.NET.net in a cross-platform solution.

Given the structure of the data that we go through, we need to include type data with information that is serialized.

We can get the type information into the stream using the TypeNameHandling property for the JsonSerializer, but we get much more information sent through the wiring.

What we would like to do is to do something similar to what MS JavaScriptSerializer does, that is, the JavaScriptTypeResolver provider, which then replaces the long type names with something much shorter.

Can this be done using JSON.NET?

+4
source share
1 answer

I think you should take a look at JSON.NET Contract Enforcers. I quote:

The IContractResolver interface provides a way to configure how the JsonSerializer serializes and deserializes .NET objects in JSON.

Implementing the IContractResolver interface and then assigning an instance to JsonSerializer allows you to control whether an object is serialized as a JSON object or a JSON array, which members of the object should be serialized, how they are serialized, and what they are called.

+5
source

Source: https://habr.com/ru/post/1346541/


All Articles