-
Notifications
You must be signed in to change notification settings - Fork 565
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
Box<RawValue>
and #[serde(flatten)]
don't work together for deserialization
#1099
Comments
As far as I can tell, this is a duplicate of #1051. That issue is about |
In the example you gave, #[derive(Deserialize, Debug)]
struct Repro {
id: String,
#[serde(flatten)]
value: Box<RawValue>,
} I find it clear that the If there's an indirection (another struct) between #![allow(dead_code)]
use serde::Deserialize;
use std::error::Error;
#[derive(Deserialize)]
struct Abc {
#[serde(flatten)]
pub def: Def,
}
#[derive(Deserialize)]
struct Def {
pub ghi: Box<serde_json::value::RawValue>,
}
fn main() -> Result<(), Box<dyn Error>> {
let _: Def = serde_json::from_str(r#"{"ghi": {}}"#).unwrap();
let _: Abc = serde_json::from_str(r#"{"ghi": {}}"#).unwrap();
Ok(())
} As we can see, the "raw json string" of the Upon re-reading #1051, I can now see how the issues are closer than I thought, so I see why it was marked as duplicate. I feel the reasoning given there doesn't apply here though. It makes sense that a raw value doesn't work if directly marked as |
I think the indirection is incidental to the reason this isn't working, so they are duplicates. It is possible to do it differently but that is tracked by serde-rs/serde#1183. |
See #883, which was mistakenly closed as being a duplicate of #1051.
The text was updated successfully, but these errors were encountered: