LitJSON / litjson

JSON library for the .Net framework
https://litjson.net/
Other
1.37k stars 404 forks source link

JsonException: Can't assign value '0' (type System.Int32) to type System.Int64 #30

Open darkcrawler01 opened 10 years ago

darkcrawler01 commented 10 years ago

I am getting this issue when I using long field with a value 0 The code I am using :

class Person
{
    public long age { get; set; }
    public Person(long age) {this.age = age;}
    public Person() { } 
}
..
string jsonString = JsonMapper.ToJson (new Person(0));
JsonMapper.ToObject<Person>(jsonString);
nicloay commented 9 years ago

i have exactly the same problem for long properties. It serialize 0 value to "value" : 0 but on deserialization give this error JsonException: Can't assign value '0' (type System.Int32) to type System.Int64

Ginurx commented 9 years ago

+1

TobyKaos commented 9 years ago

+1 And if number is small same error occur.

prestonj commented 9 years ago

I think that development on this library is dead. I've had a similar pull request sitting in the queue for awhile (to deal with cast exceptions between ints/longs). No movement.

zworp commented 8 years ago

You need to register an custom importer

        JsonMapper.RegisterImporter<int, long>((int value) =>
            { 
                return (long)value;
            });