Closed indiv0 closed 7 years ago
To what rust code do you expect it to deserialize? I have no clue how to represent interleaved sequences.
See #26 for a similar/the same case
I expect/prefer for it to deserialize to:
struct States {
state: Vec<State>,
statelist: Statelist,
}
struct Statelist {
state: Vec<State>,
}
i.e., merge the sequences into a single Vec
, as if all the elements came in order.
There can't be multiple state lists?
This is very hard to do, I'll think about it, but it'll require some intermediate allocations.
The easiest would be to manually implement deserialize for this special case
There can be multiple statelists, but I simplified it for the purposes of illustrating the example. Here's the full version of what I want.
Let me know what you've decided when you've finished thinking about it. If it's indeed too hard to handle then I guess I can write a custom deserializer.
The serde deserialization framework does not fit your use case with autogenerated deserialize impls. There's no need for a custom deserializer, since that won't help. You need to implement Deserialize
manually for States
.
I'd still say that the solution from #26 is cleaner, but I'm not sure on the usability of the struct and enum
Yeah that's what I meant by "custom deserializer". Ok I'll look into it, thanks.
Actually, I don't think I can use the solution in #26 because my elements don't specify an xsi:type
. Is there a way to deserialize those elements to an enum just on their name alone?
Yea, you need to write a MapVisitor
to get access to the names
Similar to the generic one here you can simply call a KeyDeserializer
to get the name
Well for what's its worth I ended up implementing Deserialize
manually and leaving the struct itself as-is. It seems to work. Thank you for your help. I guess this issue can be closed now.
So I basically have some XML in the form:
which fails to deserialize because the tags go
state
,statelist
,state
.However it deserializes fine if the two
state
tags come first: