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

Use String deserialization for bigInt #464

Open
Doozers opened this issue Nov 27, 2023 · 0 comments
Open

Use String deserialization for bigInt #464

Doozers opened this issue Nov 27, 2023 · 0 comments

Comments

@Doozers
Copy link

Doozers commented Nov 27, 2023

Hi,

graphql use string type to represent big integers but the rusts bigint's types deserialise expecting a tuple (sign, value) so I'm having issues to deal with big integers.

use num_bigint::BigInt;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Data {
    num: BigInt,
}

fn main() {
    let data = r#"
        {
            "num": "111111111111111111111111111111111111",
        }
    "#;

    let d: Data = serde_json::from_str(data).unwrap();
    println!("{}", d.num);
}
thread 'main' panicked at src/main.rs:16:46:
called `Result::unwrap()` on an `Err` value: Error("invalid type: string \"111111111111111111111111111111111111\", expected a tuple of size 2", line: 3, column: 57)

code example to explain the problem, but the real-case error message is:

Error: reqwest::Error { kind: Decode, source: Error("invalid type: string \"29686942926033387970\", expected a tuple of size 2", line: 1, column: 177) }

what is the best way to bypass these issues ?

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

1 participant