-
-
Notifications
You must be signed in to change notification settings - Fork 175
[Bug] Newtype enum variant deserialization failure when used with #[serde(flatten)]
#344
Comments
I just experimented with different enum representations. The results may be interesting for diagnosis: With
|
#[serde(flatten)]
To add some maybe helpful information: This was introduced with the |
Also if you serialize with 0.8 (it does not use tags) you can deserialize with 0.9, but an item serialized with 0.9 cannot be deserialized with neither. |
Same problem here. Had not expected that serde_yaml's Serializer would use a format that serde_yaml's Deserializer cannot parse, but this is exactly what is happening here. CC @dtolnay |
Your "F-22" example resembles a transphobic joke. Consider changing it. |
No. PC's gone mad these days. [Edit] rant deleted. |
I am seeing this issue as well with the |
1 similar comment
I am seeing this issue as well with the |
It seems that inside a field marked with use indoc::indoc;
use serde::Deserialize;
use std::{collections::HashMap, fmt::Debug};
#[derive(Deserialize, Debug)]
enum Inner {
A,
}
#[derive(Deserialize, Debug)]
struct Outer {
#[serde(flatten)]
flattened_field: HashMap<String, Inner>,
}
fn main() {
// doesn't work (as expected)
println!("{:?}", serde_yaml::from_str::<Inner>(indoc! {"
A: null
"}));
// works (as expected)
println!("{:?}", serde_yaml::from_str::<Inner>(indoc! {"
!A
"}));
// works (bug)
println!("{:?}", serde_yaml::from_str::<Outer>(indoc! {"
blah: { A: null }
"}));
// doesn't work (bug)
println!("{:?}", serde_yaml::from_str::<Outer>(indoc! {"
blah: !A
"}));
} This seems to be caused by I'm not sure how to fix this. Ideally the code generated by I hope some of this could help. I'd like to fix this myself, but I don't know enough about serde/rust to come up with a good fix. |
TL;DR
If you create an enum that contains a newtype variant, wrap the enum in a struct, wrap the said struct in another struct and use
#[serde(flatten)]
on it, the struct can no longer successfully deserialize (while serialization is unaffected).Deserialization fails with message:
untagged and internally tagged enums do not support enum input
.That's not a very helpful description so here's a MRE:
Misc
I tried the exact same example using
serde_json
, no errors. So I think this is aserde_yaml
issue rather than aserde
issue.A quick search did find this issue though, not sure if it's related: ron-rs/ron#217.
Versions
The text was updated successfully, but these errors were encountered: