-
-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Description
Structs with flattened argument are improperly introspected. Any introspection of such a struct results in the empty array. Cannot determine if serde_with causes unexpected behaviors, because it's dependent on the flatten
Unresolved issues
-
flattenworking as expected - verify that
serde_withprefix is working as expected
Example
ser.rs
// ser.rs
use serde::{Serialize, Deserialize};
serde_with::with_prefix!(my "my_)");
#[derive(Debug, Serialize, Deserialize)]
pub struct B {
pub b: String,
#[serde(rename="z")]
pub b2: usize
}
#[derive(Debug, Serialize, Deserialize)]
pub struct A {
pub a: usize,
#[serde(flatten, with="my")]
pub bx: B
}
#[derive(Debug, Serialize, Deserialize)]
pub struct A0 {
pub a: usize,
pub bx: B
}
#[derive(Debug, Serialize, Deserialize)]
pub struct A1 {
#[serde(with="my")]
pub a: usize
}
#[derive(Debug, Serialize, Deserialize)]
pub struct A2 {
#[serde(flatten)]
pub bx: B
}
#[derive(Debug, Serialize, Deserialize)]
pub struct A3 {
#[serde(with="my")]
pub bx: B
}main.rs
// main.rs
use serde_aux::prelude::*;
mod ser;
fn main() {
let b = ser::B {
b: "AA".into(),
b2: 22,
};
let a = ser::A {
a: 2,
bx: b.clone()
};
let a0 = ser::A0 {
a: 2,
bx: b.clone()
};
let _a1 = ser::A1 {
a: 2,
};
let a2 = ser::A2 {
bx: b.clone()
};
let a3 = ser::A3 {
bx: b.clone()
};
println!("A = \t{}", serde_json::to_string_pretty(&a).unwrap());
println!("A0 = \t{}", serde_json::to_string_pretty(&a0).unwrap());
println!("A2 = \t{}", serde_json::to_string_pretty(&a2).unwrap());
println!("A3 = \t{}", serde_json::to_string_pretty(&a3).unwrap());
println!("A = \t{:?}", serde_introspect::<ser::A>());
println!("A0 = \t{:?}", serde_introspect::<ser::A0>());
println!("A1 = \t{:?}", serde_introspect::<ser::A1>());
println!("A2 = \t{:?}", serde_introspect::<ser::A2>());
println!("A3 = \t{:?}", serde_introspect::<ser::A3>());
}stdout
# Output
A = {
"a": 2,
"my_)b": "AA",
"my_)z": 22
}
A0 = {
"a": 2,
"bx": {
"b": "AA",
"z": 22
}
}
A2 = {
"b": "AA",
"z": 22
}
A3 = {
"bx": {
"my_)b": "AA",
"my_)z": 22
}
A = [] # Wrong
A0 = ["a", "bx"] # Control sample. This is always ok
A1 = # Actually panics, my bad
A2 = [] # Wrong
A3 = ["bx"] # Actually ok, my badIizuki
Metadata
Metadata
Assignees
Labels
No labels