-
Notifications
You must be signed in to change notification settings - Fork 231
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
Unable to serialize a struct that deserialization works for #654
Comments
You do not need to rename #[serde(rename = "$value")]
pub body: SoapBody, Use usual rename, for example, It is possible to fix this behavior, although. |
I changed the #[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 #[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.
Edit: Interestingly, if I set the field to rename like this: #[serde(rename = "Body")]
pub body: SoapBody, And change the XML from |
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:
The text was updated successfully, but these errors were encountered: