-
Notifications
You must be signed in to change notification settings - Fork 231
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
Change the representation of Enums #717
Comments
You can find answer in this chapter about mapping of Rust types to XML. TL;DR: your enum variant is not a unit variant and it cannot be serialized in arbitrary-named field of struct. |
Then why does it work for Why do I have to compile different binary just for your library? Is there any way to show struct AnyName {
#[serde(rename = "$value")]
any_name: Choice,
} |
But still, even when using |
It is hard to answer to your questions because you do not provide your expectations. The mentioned piece of documentation shows how quick-xml performs mapping in a consistent manner. If you have concrete suggestions, please describe them and even better open a PR with them! |
My expectations:
Just like JSON:
|
Issue should be reopened - other crates support enum lists. |
You feel free to submit PR that would implement the desired behavior and make it in the consistent way. Probably this is possible. We also should keep the ability to use tag name as enum discriminator, because this is natural way how |
serde_json supports enums:
"field": "Unit",
"field": { "Newtype": 42 },
"field": { "Tuple": [42, "answer"] },
"field": { "Struct": {"q": 42, "a":"answer"} },
https://docs.rs/quick-xml/latest/quick_xml/de/index.html#normal-enum-variant
so quick-xml should too:
<field>Unit</field>
<field><Newtype>42</Newtype></field>
<field><Tuple>42</Tuple><Tuple>answer</Tuple></field>
<field><Struct><q>42</q><a>answer</a></Struct></field>
Currently the above XML won't be generated (gives an error) while JSON would even parse back into Rust enum.
Unsupported operation: cannot serialize enum newtype variant
Serialization of enum - crate comparison:
The text was updated successfully, but these errors were encountered: