Open tatupesonen opened 1 year ago
You do not need to rename body
to $value
here:
#[serde(rename = "$value")]
pub body: SoapBody,
Use usual rename, for example, #[serde(rename = "soapenv:Body")]
. $value
is required for enumerated types, but SoapBody
is a struct.
It is possible to fix this behavior, although.
I changed the SoapResponse
to this:
#[derive(Deserialize, Debug, Serialize)]
#[serde(rename = "soapenv:Envelope")]
pub struct SoapResponse {
#[serde(rename = "@xmlns:soapenc")]
soapenc: String,
#[serde(rename = "@xmlns:soapenv")]
soapenv: String,
#[serde(rename = "@xmlns:xsd")]
xsd: String,
#[serde(rename = "@xmlns:xsi")]
xsi: String,
#[serde(rename = "soapenv:Body")]
pub body: SoapBody,
}
and the SoapBody
:
#[derive(Deserialize, Debug, Serialize)]
#[serde(rename = "soapenv:Body")]
pub struct SoapBody {
#[serde(rename = "$value")]
pub response_type: Response,
}
Serialization works fine now, but deserialization now doesn't work. Trying to use the same XML.
Custom(
"missing field `soapenv:Body`",
),
Edit: Interestingly, if I set the field to rename like this:
#[serde(rename = "Body")]
pub body: SoapBody,
And change the XML from <soapenv:Body>
to <Body>
, now both deserialization and serialization work fine.
Yes, namespaced renames works only occasionally, in general we do not support namespaces in serde (de)serializer yet.
A trick that use to work for this case was :
#[serde(alias = "soapenv:Body", rename(serialize = "soapenv:Body"))]
pub struct SoapBody {
#[serde(rename = "$value")]
pub response_type: Response,
}
I'm trying to serialize/deserialize some data that an API responds with. This is what the XML from the API looks like:
And this is my code:
Deserialization works fine. However, when I try to serialize a structure like this:
I get
What could be the reason that causes this?
Versions: