serde-xml-rs icon indicating copy to clipboard operation
serde-xml-rs copied to clipboard

Cannot round trip through serde

Open Plecra opened this issue 5 years ago • 3 comments

Here's a minimal example:

#[derive(Debug, Serialize, Deserialize)]
struct Foo;
#[derive(Debug, Serialize, Deserialize)]
struct Bar {
    foo: Foo,
}
serde_xml_rs::from_str::<Bar>(
    &serde_xml_rs::to_string(&Bar {
        foo: Foo
    }).unwrap())
.unwrap();

Plecra avatar May 07 '20 21:05 Plecra

Yeah, I think that this is not the only example.

@dtolnay, once told me that round-tripping wasn't all that useful in practice.

@Plecra, what is your motivation for requiring this?

punkstarman avatar May 09 '20 14:05 punkstarman

Any communication between users of this crate would require the data to properly round trip through the serialised format. That might be saving a collection to disk, or sending a packet over the network.

It's also a big factor in usability - the user might be interacting with some API that has a Bar type in their data model, and if you can't rely on serialisation and deserialisation behaving the same way, you'd need to write two definitions of the same type.

...is what I would've said, but it seems so obvious to me that there might be some reason it doesn't apply here?

Plecra avatar May 10 '20 12:05 Plecra

@Plecra, I agree with you.

punkstarman avatar May 14 '20 18:05 punkstarman