Open kyle-mccarthy opened 2 months ago
Describe the bug
If a struct contains a field annotated with #[serde(flatten)], it cannot be deserialized by sonic.
#[serde(flatten)]
To Reproduce
Cargo.toml
[package] name = "repro" version = "0.1.0" edition = "2021" [dependencies] sonic-rs = "0.3.13" serde = { version = "1.0", features = ["derive"] }
main.rs
fn main() { #[derive(serde::Deserialize)] struct Repro { expected_field: i32, #[serde(flatten)] others: std::collections::HashMap<String, sonic_rs::Value>, } let json = r#" { "expected_field": 1, "unexpected_field": 2 } "#; let _repro: Repro = sonic_rs::from_str(json).unwrap(); }
Expected behavior
Deserialization to succeed and for others to contain the "unexpected_field".
others
unexpected_field
Actual behavior
thread 'main' panicked at src/main.rs:16:50: called Result::unwrap() on an Err value: invalid type: newtype struct, expected a valid json at line 5 column 4
Result::unwrap()
Err
sonic-rs version:
latest (0.3.13)
Environment:
macos
thanks, we will investigate that
the problem is similar as https://github.com/serde-rs/serde/issues/1183 and https://github.com/serde-rs/json/issues/1099
Describe the bug
If a struct contains a field annotated with
#[serde(flatten)]
, it cannot be deserialized by sonic.To Reproduce
Cargo.toml
main.rs
Expected behavior
Deserialization to succeed and for
others
to contain the "unexpected_field
".Actual behavior
thread 'main' panicked at src/main.rs:16:50: called
Result::unwrap()
on anErr
value: invalid type: newtype struct, expected a valid json at line 5 column 4sonic-rs version:
latest (0.3.13)
Environment:
macos