0

I've got a large JSON file I am trying to reduce in size, and one of the things that I noticed is that the custom JSON serializer that I am using seems to require unnecessary information about each JObject's type. An example:

{"$type": "NECode.WordWS, NECode","":""}

This is generated using the following line of code

writer.WriteRaw("""$type"": """ & obj.GetType.FullName & ", " & "NECode"",")

In this case, "NECode" is the name of the project where this class is built. Every class in the JSON file is located in this project, however. Without writing a custom deserializer (which is not practical in this case), is there a simple way to create a 'default' project name for any JSON classes. That would ideally change the above JObject to look like this:

{"$type": "WordWS","":""}

Which would be a pretty significant reduction in size. Thank you in advance!

LL201
  • 9
  • 4
  • You should be able to create a custom [`ISerializationBinder`](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Serialization_ISerializationBinder.htm). Take a look at [JSON.Net: deserializing polymorphic types without specifying the assembly](https://stackoverflow.com/q/13598969/10263), which is very similar to your question. See [Custom $type value for serialized objects](https://stackoverflow.com/q/49283251/10263); for another well-explained example (but it is only implemented for serialization in that one, so you'd need to fill in the other method to handle deserialization). – Brian Rogers Mar 26 '20 at 15:40
  • Thank you for pointing me to that answer. Just to clarify for anybody in the same boat as me, it appears you can set up a SerializationBinder and just use it for deserialization. In other words, I'll change the code in my custom serializer but then set up a SerializationBinder to be used upon deserialization to properly interpret the custom-written type information. – LL201 Mar 26 '20 at 16:05

0 Answers0