I am using Newtonsoft JSON.NET to serialize / deserialize for me. But I have this list in which they are of type Object :
var list = new List<Object>() { "hi there", 1, 2.33 };
When I serialize this with TypeNameHandling set to TypeNameHandling.All , I expected it to also give $type for each instance in the list, but it doesn't seem to be that way. Here is the actual conclusion:
{ "$type": "System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib", "$values": [ "hi there", 1, 2.33 ] }
I need that I have a specific type name processing for these primitive types, because if I add an Int32 value to the list, and when it comes back after deserialization, JSON.NET sets it to Int64 . This is very important for me, because I'm trying to call some methods and do this, I need to compare the parameters, and they MUST have the same types. Is there a way or settings that you can set in JSON.NET to achieve what I need?
I saw this post , but it does that it tries to change the default behavior and always returns Int32 , which is not what I'm looking for.
Any help would be greatly appreciated. Thanks
source share