Unable to serialize a struct that deserialization works for
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Start by reading the Serde serialization handling for $value fields and the tests covering nested structs in that position; the payload does not name specific files. Reproduce the reported error with quick-xml 0.30.0 and the SoapResponse example. Done means serialization succeeds for this structure, with a regression test covering the case.
Written by the indexing model from the issue text.
Description
I'm trying to serialize/deserialize some data that an API responds with. This is what the XML from the API looks like:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<LoginResponse xmlns="urn:vim25">
<returnval>
<userName>username_here</userName>
<loggedInAt>datetime_here</loggedInAt>
</returnval>
</LoginResponse>
</soapenv:Body>
</soapenv:Envelope>
And this is my code:
#[derive(Deserialize, Debug, Serialize)]
#[serde(rename = "soapenv:Envelope")]
pub struct SoapResponse {
#[serde(rename = "@xmlns:soapenc")]
soapenc: Option<String>,
#[serde(rename = "@xmlns:soapenv")]
soapenv: Option<String>,
#[serde(rename = "@xmlns:xsd")]
xsd: Option<String>,
#[serde(rename = "@xmlns:xsi")]
xsi: Option<String>,
#[serde(rename = "$value")]
pub body: SoapBody,
}
#[derive(Deserialize, Debug, Serialize)]
pub struct SoapBody {
#[serde(rename = "$value")]
pub response_type: Response,
}
#[derive(Deserialize, Debug, Serialize)]
pub enum Response {
#[serde(rename = "LoginResponse")]
LoginResponse {
#[serde(rename = "@xmlns")]
xmlns: String,
#[serde(rename = "$value")]
returnval: LoginResponse,
},
#[serde(rename = "Other")]
SomeOther {},
}
#[derive(Deserialize, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LoginResponse {
logged_in_at: String,
user_name: String,
}
Deserialization works fine. However, when I try to serialize a structure like this:
use quick_xml::se::to_string;
let thing = SoapResponse {
soapenc: None,
soapenv: None,
xsd: None,
xsi: None,
body: {
SoapBody {
response_type: Response::LoginResponse {
xmlns: "urn:vim25".into(),
returnval: LoginResponse {
logged_in_at: "example".into(),
user_name: "example".into(),
},
},
}
},
};
let thing = to_string(&thing);
dbg!(&thing);
I get
Err(
Unsupported(
"serialization of struct `SoapBody` is not supported in `$value` field",
),
)
What could be the reason that causes this?
Versions:
quick-xml 0.30.0 with features = ["serde", "serialize", "arbitrary", "serde-types", "overlapped-lists", "document-features", "encoding", "encoding_rs"]
Rust 1.72
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 299
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tafia/quick-xml
-
Parser accepts an empty element or attribute namePossibly taken @ychampion claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
DecodingReader::set_encoding panics when the XML declaration is longer than 64 bytesPossibly taken @emschwartz claimed this 4 days ago. Openbug encoding
Difficulty 4/5 3-5 days Newbie friendliness 30/100
tafia/quick-xml#1040 · 1 comment ·
Maintainers usually reply within 1 day
-
encoding optimization
Difficulty 4/5 3-5 days Newbie friendliness 55/100
tafia/quick-xml#1039 · 1 comment ·
Maintainers usually reply within 1 day
-
optimization question
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 1-2 days Newbie friendliness 53/100
tafia/quick-xml#1035 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
storytold/photocraft#14822 ·
Maintainers usually reply within 1 day
-
bug css
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dginev/latexml-oxide#853 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 2 days
-
[Bug] export_build_environment admits its output directory only after the export ran in the build computerPossibly taken @viniciusdsandrade claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day