You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
Yes
What did you do?
Try to decode json numbers in string format as big.Int.
What did you expect to see?
String number (e.g. {"val": "123"}) should be unmarshaled to big.Int.
What did you see instead?
String number (e.g. {"val": "123"}) can not be unmarshaled to big.Int.
Proposal
Even though the json spec does allow numbers of any size it is very common to have big numbers in string format, e.g. {"val": "123"} instead of {"val":123}. I propose to add support for reading numbers in string format to big.Int.UnmarshalJSON.
No API change, just a small improvement.
Is this not a duplicate of #36099? If we were to do this, I'd think we should restrict it to ,string, to not break the behavior of existing programs. For example, a program using big.Int right now only accepts JSON integers, and not JSON strings, so we'd be making it accept an input that it didn't before. cc @dsnet
#36099 also wants to enable string marshalling by adding ,string to big.Int.
If we were to do this, I'd think we should restrict it to ',string', to not break the behavior of existing programs.
You are right. I can't think of a reasonable use-case though where a string number as input should break things. But it will definitely break test suites.
Should I close this issue in favor of #36099? It seem to be stale.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Try to decode json numbers in string format as
big.Int
.What did you expect to see?
String number (e.g.
{"val": "123"}
) should be unmarshaled tobig.Int
.What did you see instead?
String number (e.g.
{"val": "123"}
) can not be unmarshaled tobig.Int
.Proposal
Even though the json spec does allow numbers of any size it is very common to have big numbers in string format, e.g.
{"val": "123"}
instead of{"val":123}
. I propose to add support for reading numbers in string format tobig.Int.UnmarshalJSON
.No API change, just a small improvement.
Related Issues:
The text was updated successfully, but these errors were encountered: