-
-
Notifications
You must be signed in to change notification settings - Fork 786
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
Support internally tagged enums with non-self-describing formats. #2187
Comments
I think the trouble you'll run into here is, what do you pass as fields? fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>; Where the |
That is a good point. Maybe I guess this is just a limitation of internal tagging? Maybe it should be called out in the docs. |
You can deserialize internally tagged enums from sequences, so forcing #[derive(Deserialize, Serialize, Debug)]
#[serde(tag = "tag")]
enum Internal {
Int{i: i32},
Bool{b: bool},
} |
Oh, I didn't realize that was supported. IIUC though the serializer always produces structs/maps though? But that would prevent fixing this as it would break backwards compatibility. Maybe for serde 2 😅 |
Actually, calling specific deserialization method is just a hint what data is expected, deserializer is not obliged to follow it. It is free to call any |
Right now deserialization of internally tagged enums rely on a call to
serde::Deserializer::deserialize_any
which often doesn't work well with non-self-describing formats. Ideallyserde::Deserializer::deserialize_struct
would be called instead so that theDeserializer
knows what to do.serde/serde_derive/src/de.rs
Lines 1340 to 1342 in 7e19ae8
The text was updated successfully, but these errors were encountered: