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

Can't convert integer value to Value struct. invalid type: integer -9223372036854776000 as i128 #8

Open
eddiezhou1 opened this issue Sep 2, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@eddiezhou1
Copy link

code:

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Demo {
    val_string: String,
    val_i128: i128,
    val: Value,
}
#[test]
fn test_serde_yaml() -> Result<(), serde_yaml::Error> {
    let yaml = "
        val_string: 123
        val_i128: -9223372036854776000
        val: -9223372036854776000
    ";
    let values: Demo = serde_yaml_ng::from_str(yaml).unwrap();
    Ok(())
}

output:

thread 'test_serde_yaml' panicked at src/main.rs:78:54:
called `Result::unwrap()` on an `Err` value: Error("val: invalid type: integer `-9223372036854776000` as i128, expected any YAML value", line: 4, column: 14)
@eddiezhou1 eddiezhou1 changed the title caninvalid type: integer -9223372036854776000 as i128 Can't convert integer value to Value struct. invalid type: integer -9223372036854776000 as i128 Sep 2, 2024
@acatton acatton added enhancement New feature or request good first issue Good for newcomers labels Sep 2, 2024
@acatton
Copy link
Owner

acatton commented Sep 2, 2024

There are multiple issues here:

I feel that this should be fixed the right way. Meaning we should be able to de-serialize a 128 bit integer. This involves a little bit of work, as I don't want to implement number as 128bit integer, therefore doubling the cost of numbers.

On the other side, if you don't need to de-serialize numbers that fit on more than 64 bits, we could do one of the two things:

  • You could move to i64 and call it a day
  • I could do a quick and dirty fix, which would make your code not crash, but it wouldn't be right (= it would overflow)

Otherwise, I'll ask you to wait for when I find the time to refactor numbers.rs. What do you think?

@eddiezhou1
Copy link
Author

Alright, I believe the issue should be addressed properly, and I am prepared to wait for your solution. However, if you have the time to implement a quick fix in a new branch, and I can use it locally as a crate, it would be more beneficial.

@eddiezhou1
Copy link
Author

I did a quick and dirty fix as my local crate.

@Mingun
Copy link
Contributor

Mingun commented Sep 22, 2024

Could you provide the arbitrary_precision feature like serde-json did? When it is active, internally use big numbers to store numbers.

@acatton
Copy link
Owner

acatton commented Sep 22, 2024

Could you provide the arbitrary_precision feature like serde-json did? When it is active, internally use big numbers to store numbers.

This is a great idea. I'll take a jab at it when I find the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants