-
Notifications
You must be signed in to change notification settings - Fork 88
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
Problem with 'untagged' #131
Comments
I just run into the same thing in my project: d0ba73c I'd expect this to work: #[test]
fn struct_with_flattened_untagged_enum() {
init_logger();
#[derive(Debug, Deserialize, PartialEq)]
#[serde(untagged)]
enum Enum {
A { field_a: i32 },
B { field_b: i32 },
}
#[derive(Debug, Deserialize, PartialEq)]
struct Struct {
common_int: i32,
#[serde(flatten)]
the_enum: Enum,
}
let s = r##"
<struct>
<common_int>123</common_int>
<field_a>456</field_a>
</struct>
"##;
let actual: Struct = from_str(s).unwrap();
assert_eq!(
actual,
Struct {
common_int: 123,
the_enum: Enum::A { field_a: 456 },
}
);
}
#[test]
fn struct_with_flattened_internally_tagged_enum() {
init_logger();
#[derive(Debug, Deserialize, PartialEq)]
#[serde(tag = "which")]
enum Enum {
A { field_a: i32 },
B { field_b: i32 },
}
#[derive(Debug, Deserialize, PartialEq)]
struct Struct {
common_int: i32,
#[serde(flatten)]
the_enum: Enum,
}
let s = r##"
<struct>
<common_int>123</common_int>
<which>A</which>
<field_a>456</field_a>
</struct>
"##;
let actual: Struct = from_str(s).unwrap();
assert_eq!(
actual,
Struct {
common_int: 123,
the_enum: Enum::A { field_a: 456 },
}
);
} But I get:
|
same, I believe this is related to serde-rs/serde#1183 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I try to read an element list via an untagged enum. Unfortunately, I end up in the error "Custom { field: "data did not match any variant of untagged enum Foo" }" everytime.
Are untagged enums supported by serde-xml-rs? What am I doing wrong here?
Here is an example running into the issue:
Best regards
Alex
The text was updated successfully, but these errors were encountered: