media-io / yaserde

Yet Another Serializer/Deserializer
MIT License
175 stars 57 forks source link

Nested XML with the same element names is not deserialized correctly. #110

Closed ephraimkunz closed 3 years ago

ephraimkunz commented 3 years ago

I have some XML like this I want to deserialize:

 <gedcomx>  
        <place>
            <name>Chestnut Grove, New Kent, Virginia, United States</name>
        </place>
    </gedcomx>

This XML could also contain another nested place tag, like this:

 <gedcomx>  
        <place>
            <name>Chestnut Grove, New Kent, Virginia, United States</name>
            <place resource="www.wikipedia.org">
        </place>
    </gedcomx>

I have these Rust structs:

#[derive(YaDeserialize, Default, Debug)]
struct Gedcomx {
    #[yaserde(rename = "place")]
    places: Vec<PlaceDescription>,
}

#[derive(YaDeserialize, Default, Debug)]
struct PlaceDescription {
    place: Option<ResourceReference>
    name: String,
}

#[derive(Debug, YaDeserialize, Default)]
pub struct ResourceReference {
    #[yaserde(attribute)]
    pub resource: String,
}

However I'm not able to deserialize this correctly. When I try on the first or the second XML example I get:

Gedcomx {
    places: [
        PlaceDescription {
            place: Some(
                ResourceReference {
                    resource: "",
                },
            ),
            name: "",
        },
    ],
}
scottlamb commented 3 years ago

Looks similar to #76.