Skip to content

u128 doesn't work for Value #502

@alexeuler

Description

@alexeuler

Looks like there's a bug in serde_json. This program:

#[macro_use]
extern crate serde_json;
use std::str::FromStr;

fn main() {
    let string = format!("{}", u128::max_value());
    println!("{}", string);
    let val = serde_json::value::Value::from_str(&string);
    let val2 = serde_json::to_value(u128::max_value());
    println!("{:#?}, {:#?}", val, val2);
}

outputs:

340282366920938463463374607431768211455
Ok(
    Number(
        340282366920938500000000000000000000000.0
    )
), Err(
    Error("u128 is not supported", line: 0, column: 0)
)

playground

if you put arbitrary_precision feature, then Value works 100% without cutting precision, if you do it via u128 => String => Value. However direct conversion u128 => Value with to_value results in error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions