JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.81k stars 3.26k forks source link

Int64 overflow not working for certain ranges #600

Closed Finglas closed 9 years ago

Finglas commented 9 years ago

When deserializing a string value that has been provided as a literal integer value then JSON.NET doesn't work in all cases. See the example below to reproduce.

I've added additional information at StackOverflow.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Sending in: \n43443333222211111117");
        var largeBrokenNumber = JsonConvert.DeserializeObject<Foo>("{\"Blah\": 43443333222211111117 }");
        Console.WriteLine(largeBrokenNumber.Blah);

        Console.WriteLine();

        Console.WriteLine("Sending in: \n53443333222211111117");
        var largeOddWorkingNumber = JsonConvert.DeserializeObject<Foo>("{\"Blah\": 53443333222211111117 }");
        Console.WriteLine(largeOddWorkingNumber.Blah);
    }
}

public class Foo
{
    public string Blah { get; set; }
}

A few points to note:

JamesNK commented 9 years ago

This has been fixed. It will be in next release.