I am using Newtonsoft JSON.NET to serialize/deserialize stuff for me. But I have this list wherein they are of Object
type:
var list = new List<Object>()
{
"hi there",
1,
2.33
};
When I serialize that with TypeNameHandling
set to TypeNameHandling.All
, I was expecting that it will also give a $type
for each instance on the list but doesn't seem to be the case. Here is the actual output:
{
"$type": "System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib",
"$values": [
"hi there",
1,
2.33
]
}
I need this to have specific Type Name Handling for those primitive types because if I add an Int32
value in to the list and when it comes back after deserializing it JSON.NET sets it as Int64
. That is a big deal for me because I am trying to invoke some methods and to do that I need to compare the parameters and they MUST have the same types. Is there a way or a setting you can set in JSON.NET to achieve what I need?
I've seen this post but what it does is that he is trying to change the default behavior and always return Int32
which is not what I'm looking for.
Any help would be appreciated. Thanks