You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now I'm able to deserialize this into one of the structs easily following the documentation:
impl<'de> Deserialize<'de> for MyEnum {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
UntaggedEnumVisitor::new()
.map(|map| {
let deserialized_map = map.deserialize().map(MyEnum::Variant1);
deserialized_map
})
.deserialize(deserializer)
}
}
However I seem to be unable to attempt to deserialize it to multiple types of structs and get the best one. I assume this might have something to do with the fact that UntaggedEnumVisitor doesn't buffer the content, while it seems that serde does that internally via _serde::__private::de::Content.
Things I have tried.
Calling .map multiple times on the UntaggedEnumVisitor
Attempting to call map.deserialize() multiple times.
Attempting to clone the map closure parameter
I'm not sure if I'm missing something, if this is a docs improvement, or we need some sort of handle to persist the values of a map to allow for multiple deserialization attempts.
The text was updated successfully, but these errors were encountered:
This isn't something I would want to address in this crate. But I would welcome someone building a more fully featured library for untagged enum deserialization logic, based on this one, where you could express things like "if it has an 'x' field, do this, else if it has a 'y' field, do this."
I'm looking to deserialize an untagged enum into one of multiple structs.
Example of the enum I would like to use serde-untagged to serialize:
Now I'm able to deserialize this into one of the structs easily following the documentation:
However I seem to be unable to attempt to deserialize it to multiple types of structs and get the best one. I assume this might have something to do with the fact that
UntaggedEnumVisitor
doesn't buffer the content, while it seems that serde does that internally via_serde::__private::de::Content
.Things I have tried.
.map
multiple times on theUntaggedEnumVisitor
map.deserialize()
multiple times.map
closure parameterI'm not sure if I'm missing something, if this is a docs improvement, or we need some sort of handle to
persist
the values of a map to allow for multiple deserialization attempts.The text was updated successfully, but these errors were encountered: