spanner: JSON number decode precision error #8669
Labels
api: spanner
Issues related to the Spanner API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Issue
When JSON data contains a number, then decoding it to
NullJson
leads to loss of precision.Test case to reproduce
The output of the above test case is
The expected output is
145688415796432520
, but the returned output is145688415796432500
.Code causing the issue
In decodeValue() function in value.go, looking at the switch case when interface is *NullJson. The code uses,
The json package in golang by default considers the numbers in
JSON
asfloat64
values. The documentation is attached below,Attaching the debugger output where the number is converted to float by the json package.
References
https://stackoverflow.com/questions/16946306/preserve-int64-values-when-parsing-json-in-go
https://stackoverflow.com/questions/24480835/decoding-json-int-into-string
golang/go#42246
The text was updated successfully, but these errors were encountered: