Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serde deserialize, attribute and child element share the same name #293

Closed
void-dragon opened this issue Jul 3, 2021 · 1 comment
Closed
Assignees
Labels
enhancement serde Issues related to mapping from Rust types to XML

Comments

@void-dragon
Copy link

i have a funny problem parsing COLLADA xml documents:

<skin source="#Cylinder_002-mesh">
        <source id="Armature_JointBase_001-skin-joints"> .. </source>
</skin>

And i is not clear how the Rust code has to look to parse something like this.

My naive approach was something like this:

#[derive(Deserialize)]
pub struct Skin {
    #[serde(rename = "source")]
    pub sources: Vec<SkinSource>,
}

#[derive(Deserialize)]
pub enum SkinSource {
    Source{id: String},
    Attr(String),
}

But this did not work.

@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML labels May 21, 2022
@Mingun Mingun self-assigned this May 21, 2022
@Mingun
Copy link
Collaborator

Mingun commented Sep 19, 2023

Since version 0.27.0 this is solved by prepending @ to the names of attributes. The original task can be solved by this types:

#[derive(Deserialize)]
pub struct Skin {
    #[serde(rename = "@source")]
    pub source: String,

    #[serde(rename = "source")]
    pub sources: Vec<SkinSource>,
}

#[derive(Deserialize)]
pub struct SkinSource {
    #[serde(rename = "@id")]
    id: String,
}

Fixed by #490.

@Mingun Mingun closed this as completed Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants