-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
Im having trouble deserializing with prefixes
#[derive(YaSerialize, YaDeserialize, Debug, Default, Clone, Eq, PartialEq)]
pub struct Header {}
#[derive(YaSerialize, YaDeserialize, Debug, Default, Clone, Eq, PartialEq)]
#[yaserde(
rename = "Envelope",
namespaces = {
"soapenv" = "http://schemas.xmlsoap.org/soap/envelope/",
},
prefix = "soapenv"
)]
pub struct SoapEnvelope<BODY>
where
BODY: YaSerialize + YaDeserialize + Default,
{
#[yaserde(rename = "Header", prefix = "soapenv")]
pub header: Option<Header>,
#[yaserde(rename = "Body", prefix = "soapenv")]
pub body: BODY,
}
#[derive(YaSerialize, YaDeserialize, Debug, Default, Clone, Eq, PartialEq)]
struct Body {
#[yaserde(prefix = "urn")]
text: String,
}
serializing the following:
let b = Body {
text: "hello world".to_string(),
};
let env = SoapEnvelope {
body: b,
..Default::default()
};
let s = yaserde::ser::to_string(&env).unwrap();
dbg!(s);this yields:
"<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope" >
<soapenv:Body>
<urn:text>hello world</urn:text>
</soapenv:Body>
</soapenv:Envelope>the text elements is serialized with the prefix
let envelope = yaserde::de::from_str::<SoapEnvelope<Body>>(&s).unwrap();this now errors with value: "text is a required field of Body"
when the prefix is removed from the text element it will serialize without a problem
"<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope" >
<soapenv:Body>
<text>hello world</text>
</soapenv:Body>
</soapenv:Envelope>if this xml is deserialized with the urn prefix on the text element. the prefix is ignored and the xml is deserialized without error..
so it seems that the deserializer is ignoring the prefix.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels