Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Out of order list of tags deserialization error #33

Closed
indiv0 opened this issue Dec 16, 2016 · 11 comments
Closed

Out of order list of tags deserialization error #33

indiv0 opened this issue Dec 16, 2016 · 11 comments

Comments

@indiv0
Copy link

indiv0 commented Dec 16, 2016

So I basically have some XML in the form:

<states>
  <state />
  <statelist>
    <state />
    <state />
  </statelist>
  <state />
</states>

which fails to deserialize because the tags go state, statelist, state.

However it deserializes fine if the two state tags come first:

<states>
  <state />
  <state />
  <statelist>
    <state />
    <state />
  </statelist>
</states>
@oli-obk
Copy link

oli-obk commented Dec 17, 2016

To what rust code do you expect it to deserialize? I have no clue how to represent interleaved sequences.

@oli-obk
Copy link

oli-obk commented Dec 17, 2016

See #26 for a similar/the same case

@indiv0
Copy link
Author

indiv0 commented Dec 17, 2016

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.

@oli-obk
Copy link

oli-obk commented Dec 17, 2016

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

@indiv0
Copy link
Author

indiv0 commented Dec 17, 2016

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.

@oli-obk
Copy link

oli-obk commented Dec 17, 2016

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

@indiv0
Copy link
Author

indiv0 commented Dec 17, 2016

Yeah that's what I meant by "custom deserializer". Ok I'll look into it, thanks.

@indiv0
Copy link
Author

indiv0 commented Dec 17, 2016

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?

@oli-obk
Copy link

oli-obk commented Dec 17, 2016

Yea, you need to write a MapVisitor to get access to the names

@oli-obk
Copy link

oli-obk commented Dec 17, 2016

Similar to the generic one here you can simply call a KeyDeserializer to get the name

@indiv0
Copy link
Author

indiv0 commented Dec 17, 2016

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.

@oli-obk oli-obk closed this as completed Dec 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants