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

Roundtripping any int64 through a serialized format (like JSON) should not lose/alter data #3

Open
luxas opened this issue Aug 30, 2021 · 2 comments

Comments

@luxas
Copy link
Owner

luxas commented Aug 30, 2021

By default, encoding/json decodes all JSON numbers into float64. Due to the nature of how float64's work, it can store integers "only" in the range [-2^53, 2^53] (see https://en.wikipedia.org/wiki/Double-precision_floating-point_format#Precision_limitations_on_integer_values and https://datatracker.ietf.org/doc/html/rfc8259#section-6).

Illustration: https://play.golang.org/p/mpZK8T1NChA

Kubernetes requires round-trips to work for all 64-bit (signed) integers; and has hence built machinery here and here to fix this by first trying to decode the JSON number (at that point represented as a string) first using strconv.ParseInt() and then, only if that fails, strconv.ParseFloat.

The JSON package of deklarative shall have this feature built-into the decoder, and use it as the default mode.

@luxas
Copy link
Owner Author

luxas commented Aug 30, 2021

It can be clarified that yaml.v2 and yaml.v3 implement the k8s logic described correctly by default to let integers round-trip successfully.

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

No branches or pull requests

2 participants
@luxas and others