-
Notifications
You must be signed in to change notification settings - Fork 30
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
Enum support #90
Comments
After looking into it for a while, it seems that the problem is at fn deserialize_enum<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
match self {
Variant::Object(o) => {
Deserializer::from_wbem_class_obj(o).deserialize_enum(name, fields, visitor)
}
_ => self.deserialize_any(visitor), // This line here
}
}
Another evidence for that is the same piece of code at fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>
where
V: Visitor<'de>,
{
let (variant, value) = match self {
Value::Object(value) => {
let mut iter = value.into_iter();
let (variant, value) = match iter.next() {
Some(v) => v,
None => {
return Err(serde::de::Error::invalid_value(
Unexpected::Map,
&"map with a single key",
));
}
};
// enums are encoded in json as maps with a single key:value pair
if iter.next().is_some() {
return Err(serde::de::Error::invalid_value(
Unexpected::Map,
&"map with a single key",
));
}
(variant, Some(value))
}
Value::String(variant) => (variant, None),
other => {
return Err(serde::de::Error::invalid_type(
other.unexpected(),
&"string or map",
));
}
};
visitor.visit_enum(EnumDeserializer { variant, value }) // This line here
} This is implemented for their |
Hi @omer54463 , I think you are right - there should be an equivalent Based on your comments, I added an initial impl at #91, but I want to add another test with more enum options (as well as failed-to-desr test). I might have time to continue next weekend, but if you want to work on it, I'll be happy to accept a more complete PR 🥳 |
Just did on #92 |
I would like to represent string fields in a WMI object as enums, but the following doesn't currently work:
It fails with the error:
Is this intended? I assume it isn't.
I tried to tackle the issue myself, but it seems I don't know
serde
good enough to do so.The text was updated successfully, but these errors were encountered: