It looks like u128 is not supported with #[serde(flatten)] when deserializing JSON. The following snippet shows the problem.
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Foo {
a: u128,
}
#[derive(Debug, Deserialize)]
struct Bar {
foo: Foo,
}
#[derive(Debug, Deserialize)]
struct Baz {
#[serde(flatten)]
foo: Foo,
}
fn main() {
println!("{:?}", serde_json::from_str::<Foo>(r#"{"a":340282366920938463463374607431768211455}"#));
println!("{:?}", serde_json::from_str::<Bar>(r#"{"foo":{"a":340282366920938463463374607431768211455}}"#));
println!("{:?}", serde_json::from_str::<Baz>(r#"{"a":340282366920938463463374607431768211455}"#));
}
Outputs:
Ok(Foo { a: 340282366920938463463374607431768211455 })
Ok(Bar { foo: Foo { a: 340282366920938463463374607431768211455 } })
Err(Error("u128 is not supported", line: 1, column: 45))
This might be a serde_derive issue though, and not related to serde_json.
It looks like
u128is not supported with#[serde(flatten)]when deserializing JSON. The following snippet shows the problem.Outputs:
This might be a
serde_deriveissue though, and not related toserde_json.