Open Dzordzu opened 7 months ago
Hi! Thank you for filing your issue! I am not aware of how it should work together (not usually use serde_with), can you please provide the examples with the expected results?
Sure. Here you go. I've edited my bug report to include jsons
So it MAY work with serde_with
prefixing, but it certainly fails with the flattened structs
I have just noticed you use the serde_introspect
crate, which is not a part of serde_aux
. Also, I couldn't see any use of serde_aux
here except for the use
statements, which do not do anything independently. Perhaps you meant to file an issue in the serde_introspect
crate instead?
Que? There is no such a crate... Also https://github.com/iddm/serde-aux/blob/master/src/serde_introspection.rs#L35
I couldn't see any use of serde_aux here except for the use statements, which do not do anything independently
I literally took it from this repo. See docs
Que? There is no such a crate... Also https://github.com/iddm/serde-aux/blob/master/src/serde_introspection.rs#L35
I couldn't see any use of serde_aux here except for the use statements, which do not do anything independently
I literally took it from this repo. See docs
Oh, I apologise! It wasn't me who added it, and I had completely forgotten about its existence.
The serde
attributes often mess up with everything else. It has been long known, and unfortunately, not many things can be fixed. From what I can tell right now, it seems that the problem is introduced by using the serde
's flatten
attribute. Additionally, the serde_with
might be breaking things another way. It is going to require research, which I unfortunately have no time for. @lucatrv would you like to take a look at what might cause a problem here?
It wasn't me who added it,
No worries, it's the beauty of the OS projects ;)
@lucatrv would you like to take a look at what might cause a problem here?
Thanks a lot!
And obviously, thanks for your effort in maintaining this project!
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 theflatten
Unresolved issues
flatten
working as expectedserde_with
prefix is working as expectedExample
ser.rs
```rust // 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
```rust // 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::
stdout
```bash # 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 bad ```