Skip to content

Forward enum deserializing does not work with collection types #124

Description

@vshashi01
#[derive(Debug, FromXml, PartialEq, ToXml)]
#[xml(forward)]
enum FooCollection {
    Bar(Vec<Bar>),
    Baz(Vec<Baz>),
}

#[derive(Debug, FromXml, PartialEq, ToXml)]
struct CollectionOwner {
    collection: FooCollection,
}

#[test]
fn wrapped_enum_collection() {
    let v = CollectionOwner {
        collection: FooCollection::Bar(vec![Bar { bar: 42 }, Bar { bar: 56 }]),
    };
    let xml =
        r#"<CollectionOwner><Bar><bar>42</bar></Bar><Bar><bar>56</bar></Bar></CollectionOwner>"#;
    assert_eq!(xml, to_string(&v).unwrap()); //this produces the expected result
    assert_eq!(v, from_str(xml).unwrap()); //this fails because only the first bar element is deserialized
}

I can help to fix this as well, however its not super clear to me where exactly the fix shall be? Should the macro generated deserialize_forward_enum account for this or the from_str implementation itself should account for multiple element case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions