I have a very simply program that gets a json blob and is supposed to deserialize it to an object (users can decide the structure themselves so can't type it).
When deserializing it for some reason makes even small numbers into long.
Here is an example:
using System.Collections.Generic;
using Newtonsoft.Json;
public class Jsontest
{
public static void testJson()
{
var simpleString = "[{\"name\":\"Item 1\",\"check\":1,\"num\":2}]";
var list = new List<CustomObj>();
list.AddRange(JsonConvert.DeserializeObject<IEnumerable<CustomObj>>(simpleString));
return list;
}
}
public class CustomObj
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonExtensionData]
public IDictionary<string, object> PropertyValues { get; set; }
}
When hitting the return breakpoint I get this data: (Apologize for the bad visualisation, also shown In Visual Studio)
PropertyValues Count = 2 System.Collections.Generic.IDictionary<string, object> {System.Collections.Generic.Dictionary<string, object>}
- [0] {[check, 1]} System.Collections.Generic.KeyValuePair<string, object>
Key "check" string
Value 1 object {long}
- [1] {[num, 2]} System.Collections.Generic.KeyValuePair<string, object>
Key "num" string
Value 2 object {long}
This data is used in a different assembly where I expect it to be an int but it appears as long. Any ideas what I am doing wrong here?