Open riverar opened 1 year ago
Hello @riverar,
You have to understood YaSerDe works quasi like XML.
namespace
defines a list of namespaces.
In addition, the prefix
will said which namespace will be used.
So try something like:
use yaserde_derive::YaDeserialize;
#[derive(YaDeserialize, Debug)]
#[yaserde(
prefix = "aaa",
namespace = "aaa"
)]
struct Root
{
#[yaserde(rename = "Child", prefix = "aaa")]
children: Vec<Child>
}
#[derive(YaDeserialize, Debug)]
#[yaserde(
prefix = "aaa",
namespace = "aaa"
)]
struct Child
{
#[yaserde(attribute, prefix = "aaa")]
a: String
}
maybe the difference is the usage of default prefix. Where with YaSerDe all namespaces requires to be mentioned to constraint.
Hey @MarcAntoine-Arnaud, thanks for the quick reply. Your sample still captures the <bbb:Child a="42" />
.
Here's the runnable version:
use yaserde_derive::YaDeserialize;
#[derive(YaDeserialize, Debug)]
#[yaserde(
namespace = "aaa"
)]
struct Root
{
#[yaserde(rename = "Child", prefix = "aaa")]
children: Vec<Child>
}
#[derive(YaDeserialize, Debug)]
#[yaserde(
prefix = "aaa",
namespace = "aaa"
)]
struct Child
{
#[yaserde(attribute, prefix = "aaa")]
a: String
}
fn main()
{
let xml = r#"
<Root xmlns="aaa" xmlns:bbb="bbb">
<Child a="1" />
<Child a="2" />
<bbb:Child a="42" />
</Root>
"#;
let doc = yaserde::de::from_str::<Root>(xml).unwrap();
dbg!(doc);
}
it seems a conflict between namespace matching. Very good and deep case !
When deserializing xml into structures with yaserde namespace attributes affixed, I am seeing deserialized elements that do not belong in the specified namespace.
Example below.
cargo.toml
main.rs
output
I did not expect
<bbb:Child a="42" />
to deserialize or show up in the result set.