gson.fromJson(json, Object.class) and gson.fromJson(json, Number.class)by default parse any numeric input as a Double even when the input is actually an integer. This PR uses the setObjectToNumber() and setNumberToNumber() functions to change the parsing strategy to LONG_OR_DOUBLE so that (small enough) integers are read as Long and only true floating-point numbers (or very large integers) are read as Double. This feels like a more reasonable default for two reasons:
Using Long whenever possible is more accurate.
Floating-point numbers suggest that rounding is acceptable when really it may not be.
gson.fromJson(json, Object.class)
andgson.fromJson(json, Number.class)
by default parse any numeric input as aDouble
even when the input is actually an integer. This PR uses thesetObjectToNumber()
andsetNumberToNumber()
functions to change the parsing strategy toLONG_OR_DOUBLE
so that (small enough) integers are read asLong
and only true floating-point numbers (or very large integers) are read asDouble
. This feels like a more reasonable default for two reasons:Long
whenever possible is more accurate.