xml icon indicating copy to clipboard operation
xml copied to clipboard

Preserve order while deserializing

Open futile opened this issue 8 years ago • 4 comments

Assume the following xml:

<parent>
  <objA/>
  <objB/>
  <objA/>
</parent>

How can I deserialize this in a fashion that preserves the order 'objA' 'objB' 'objA'?

Deserializing into a Vec<ObjA> and a Vec<ObjB> would not preserve the information that the single ObjB was deserialized between the other two.

I guess in this case an enum like enum Obj { ObjA, ObjB}, and then a Vec<Obj> would make sense, but from what I saw in the tests this only works when the xml looks like <obj xsi:type="ObjA"> etc.

Is there a good way to do this (without deserializing the whole parent manually)?

futile avatar Sep 07 '16 21:09 futile