Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math/big: Support string numbers in Int.UnmarshalJSON #49525

Closed
lmittmann opened this issue Nov 11, 2021 · 3 comments
Closed

math/big: Support string numbers in Int.UnmarshalJSON #49525

lmittmann opened this issue Nov 11, 2021 · 3 comments

Comments

@lmittmann
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.17.3

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.

Related Issues:

@mvdan
Copy link
Member

mvdan commented Nov 12, 2021

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

@lmittmann
Copy link
Author

Is this not a duplicate of #36099?

#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.

@seankhliao
Copy link
Member

Duplicate of #36099

@seankhliao seankhliao marked this as a duplicate of #36099 Nov 12, 2021
@golang golang locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants