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

HTTP unmarshal a number into an interface{} as json.Number instead of float64 #1407

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aniketnk
Copy link

@aniketnk aniketnk commented Jan 12, 2025

fixes #1163

reference: https://pkg.go.dev/encoding/json#Decoder.UseNumber

UseNumber causes the Decoder to unmarshal a number into an interface{} as a Number instead of as a float64.

Changes

  • Use json.Decoder with UseNumber option to unmarshal the JSON object received from http handler.
  • Added a testcase for math.MinInt64.
  • Added testcases for errors.

Output

SET

curl --location --request GET 'localhost:8082/set' \
--header 'Content-Type: application/json' \
--data '{
    "key" : "a",
    "value" : -9223372036854775808
}'
{"status":"success","data":"OK"}

GET

curl --location --request GET 'localhost:8082/get' \
--header 'Content-Type: application/json' \
--data '{
    "key" : "a"
}'
{"status":"success","data":-9223372036854775808}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant