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
Option<bool> doesn't (de)serialize properly with serde #497
Comments
Test case minimized from djkoloski/rust_serialization_benchmark#34 |
This is using the current master branch ^^ |
This bug is not specific to <root/> <!-- (1) None -->
<root><element/></root> <!-- (2) ? -->
<root><element>$DATA</element></root> <!-- (3) Some(...) --> While result for (1) and (3) are pretty obvious, that is hard to say for (2). The JSON equivalent of that structs is {}
{ "element": null }
{ "element": $DATA } How we should map the case (2)? quick-xml currently does the opposite: it always deserializes to Fixing that likely will have a consequence, that |
Would it be possible to use a special attribute value, e.g. |
I would try to avoid that and use |
Actually, that case is much more complex then I thought initially. It is unclear, how to process cases like <element attribute="..."/> At time of deciding if we should return struct Struct {
#[serde(rename = "@attribute")]
attribute: (),
} then this XML snippet are definitely not Because of the nature of XML we like to keep ability to deserialize things like <element attribute="...">
content
</element> into a String {
"@attribute": "...",
"$text": "content"
} and could not be deserialized into a <element attribute="..."/> into an <element/> which suggested to be |
Is there any update on this, or maybe some kind of workaraound? Currently the only way I cound get the serialization of an optional value to work is when the target type is |
The simplest workaround I found if you control both the serializing and de-serializing parts is to use the following serde attributes: This problem is still quite bothersome though... |
Using the following code:
The code crashes during the deserialize step
If instead
spawn_forced
is set toSome(true)
orSome(false)
, it works fine. OnlyNone
, which serializes to<spawn_forced/>
, panics upon deserialization.The text was updated successfully, but these errors were encountered: