magiclen/Byte-Unit

Deserialization fails with "invalid type: map, expected a byte"

Closed this issue · 2 comments

Any help understanding how to fix this appreciated :)

Example code:

extern crate byte_unit;
use byte_unit::Byte;

fn main() {
  let payload = r#"40000000000000"#;
  let deserialized = serde_json::from_str::<Byte>(payload);
  dbg!(&deserialized);
}

error message:

[src/main.rs:7] &deserialized = Err(
    Error("invalid type: map, expected a byte such as 123, \"123\", \"123KiB\" or \"50.84 MB\"", line: 1, column: 14),
)

Replacing Byte with u128 works without an issue.

Cargo.toml:

...
[dependencies]
serde = { version = "1.0.117", features = ["derive"] }
serde_json = { version = "1.0.64", features = ["arbitrary_precision"] }
byte-unit = { version = "4.0.12", features = ["serde"] }

Your code works fine when the arbitrary_precision feature of the serde_json crate is off.

right, thanks, just verified it and that's correct