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

Attribute does not serialize in enum #149

Open
sobczyk opened this issue Nov 4, 2022 · 2 comments
Open

Attribute does not serialize in enum #149

sobczyk opened this issue Nov 4, 2022 · 2 comments

Comments

@sobczyk
Copy link

sobczyk commented Nov 4, 2022

use yaserde_derive::YaSerialize;

#[derive(Default, YaSerialize)]
struct A
{
    #[yaserde(attribute)]
    val: u8
}
#[derive(Default, YaSerialize)]
struct B
{
    val: u8
}
#[derive(YaSerialize)]
enum MainNode
{
    A(A),
    B(B),
}

#[derive(Default, YaSerialize)]
struct Main
{
    #[yaserde(child, flatten)]
    m: Vec<MainNode>
}

fn sample() -> Main {
    Main {
        m: vec![
            MainNode::A(
                A{val: 1}
                ),
            MainNode::B(
                B{val: 2}
                )
        ]
    }
}
fn main()
{
    let node = sample();
    println!("{}", yaserde::ser::to_string(&node).unwrap());
}

#[cfg(test)]
mod tests {
    const XML: &str = r##"<?xml version="1.0" encoding="utf-8"?><Main><A val="1" /><B><val>2</val></B></Main>"##;
    use crate::sample;
    #[test]
    fn attribute() {
        let node = sample();
        let data = yaserde::ser::to_string(&node).unwrap();
        assert_eq!(data, XML);
    }
}

the A::val is not serialized from Main structure.

@OkieOth
Copy link

OkieOth commented Dec 10, 2023

I have the same issue and will try to debug.

@OkieOth
Copy link

OkieOth commented Dec 11, 2023

Found something and created a PR #167

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

2 participants