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.
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 ande
signifiers, the SimpleJson code will only attempt to parse them aslong
. This means that the (valid) JSON string produced by(long.MaxValue + 1M).ToString()
cannot be parsed. This PR addresses the issue (usingdecimal
and thendouble
as fallbacks wherelong
fails), and adds corresponding unit tests.