Skip to content

xdrjson: Rust: Render 64-bit integers as strings #181

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

Closed
leighmcculloch opened this issue Nov 13, 2023 · 6 comments · Fixed by #213
Closed

xdrjson: Rust: Render 64-bit integers as strings #181

leighmcculloch opened this issue Nov 13, 2023 · 6 comments · Fixed by #213
Assignees

Comments

@leighmcculloch
Copy link
Member

What

Render 64-bit integers as strings in JSON.

Why

JS runtimes cannot correctly decode JSON numbers greater than 53-bits.

@leighmcculloch
Copy link
Member Author

leighmcculloch commented Nov 25, 2023

Given that so many tools support 64-bit integers in JSON I'm thinking maybe we should follow a pattern I've heard folks using, where the 64-bit integer is encoded into two fields, in a number in a field by it's native name, and in a string in a field by its native name suffixed with _str.

For example:

{
    "my_field": 1,
    "my_field_str": "1",
    // ...

The downside of this is that someone may still use the my_field in JS and unknowingly be interpreting the JSON data as a Number with lost precision.

@leighmcculloch leighmcculloch changed the title Rust: Render 64-bit integers as strings in JSON Rust: Render 64-bit and larger integers as strings in JSON Mar 21, 2024
@leighmcculloch leighmcculloch changed the title Rust: Render 64-bit and larger integers as strings in JSON Rust: Render 64-bit integers as strings in JSON Apr 7, 2025
@leighmcculloch
Copy link
Member Author

leighmcculloch commented Apr 7, 2025

If 64-bit integers become rendered as strings, and 128-bit and 256-bit integers also become rendered as strings (stellar/rs-stellar-xdr#430), should XDR-JSON render 32-bit integers as strings for consistency?

@leighmcculloch leighmcculloch changed the title Rust: Render 64-bit integers as strings in JSON XDR-JSON: Rust: Render 64-bit integers as strings Apr 16, 2025
@leighmcculloch leighmcculloch changed the title XDR-JSON: Rust: Render 64-bit integers as strings xdr-json: Rust: Render 64-bit integers as strings Apr 16, 2025
@leighmcculloch leighmcculloch changed the title xdr-json: Rust: Render 64-bit integers as strings xdrjson: Rust: Render 64-bit integers as strings Apr 16, 2025
@Shaptic
Copy link
Contributor

Shaptic commented Apr 21, 2025

@leighmcculloch I would prefer using number of 32 bits - this aligns with other APIs and follows a "native support when possible" approach.

@kalepail
Copy link

I too am in favor of a "native support when possible" approach though I don't feel strongly about this. As long as whatever we use BigInt works with (which right now it doesn't as we use the JSON hi lo stuff) I'm good with

@leighmcculloch
Copy link
Member Author

@leighmcculloch
Copy link
Member Author

Opened issue on serde_json about difficulty specifying 64-bit integers serialize when they are inside other types:

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

Successfully merging a pull request may close this issue.

3 participants