facebook-csharp-sdk / simple-json

JSON library for .NET 2.0+/SL4+/WP7/WindowsStore with optional support for dynamic and DataContract
MIT License
382 stars 143 forks source link

Allow deserialization of very large integers #75

Open logiclrd opened 8 years ago

logiclrd commented 8 years ago

While I was working on a PR for RestSharp, I was reading through the SimpleJson code and discovered that the way in which it parses integers might reject some syntactically-valid JSON documents. In particular, JSON allows for very large integer values to be specified (values large enough that a 64-bit integer cannot represent them) with no punctuation or exponentiation. These values would, in typical implementations, need to be represented as floating-point values (double), but because they lack periods and e signifiers, the SimpleJson code will only attempt to parse them as long. This means that the (valid) JSON string produced by (long.MaxValue + 1M).ToString() cannot be parsed. This PR addresses the issue (using decimal and then double as fallbacks where long fails), and adds corresponding unit tests.