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

Using flatten with namespaces #138

Open
luke-biel opened this issue Feb 15, 2022 · 0 comments
Open

Using flatten with namespaces #138

luke-biel opened this issue Feb 15, 2022 · 0 comments

Comments

@luke-biel
Copy link

I will take liberty with opening new issue with this one. I'm looking for an information how to use namespaces with flatten.
Eg.:

use yaserde_derive::YaDeserialize;

#[derive(Default, YaDeserialize)]
#[yaserde(
    root = "Root",
    prefix = "nsa",
    namespace = "nsa: http://nsa.com",
    namespace = "nsb: http://nsb.com"
)]
struct Root {
    #[yaserde(rename = "Root.basic", prefix = "nsa", text)]
    basic: String,
    #[yaserde(flatten)]
    child: Child,
}

#[derive(Default, YaDeserialize)]
struct Child {
    #[yaserde(rename = "Child.param", prefix = "nsa", text)]
    param: String,
    #[yaserde(flatten)]
    child2: Child2,
}

#[derive(Default, YaDeserialize)]
struct Child2 {
    #[yaserde(rename = "Child2.param", prefix = "nsb", text)]
    param: String,
}

#[cfg(test)]
mod tests {
    use crate::Root;

    #[test]
    fn parses() {
        const XML: &str = r##"
        <nsa:Root xmlns:nsa="http://dupa.com" xmlns:nsb="http://nsb.com" >
            <nsa:Root.basic>Value</nsa:Root.basic>
            <nsa:Child.param>ValueC</nsa:Child.param>
            <nsb:Child2.param>ValueD</nsb:Child2.param>
        </nsa:Root>
        "##;

        let _: Root = yaserde::de::from_str(XML).unwrap();
    }
}

Doesn't work.

As a background: I'm working on rust code generated from inheritance model. I would prefer to avoid manual flattening of these structs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant