Unable to serialize a struct that deserialization works for
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Rust
- スター
- 1.6k
- フォーク
- 299
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tafia/quick-xml のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
DecodingReader::set_encoding panics when the XML declaration is longer than 64 bytes対応中かも @emschwartz が 4 日前に担当しました。 オープンbug encoding
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
tafia/quick-xml#1040 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
encoding optimization
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
tafia/quick-xml#1039 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
optimization question
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 1〜2日 初心者へのやさしさ 53/100
tafia/quick-xml#1035 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
tafia/quick-xml の issue をすべて見る
似ている issue
-
[Bug]: opencode_go chat route drops reasoning_effort (even 'none'), while the same endpoint honors it via custom_llm_provider=openai対応中かも @arvindkumar-ship-it が今日担当しました。 オープンllm translation
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
BerriAI/litellm#51871 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
comp-formats
難易度 2/5 半日 初心者へのやさしさ 64/100
ClickHouse/ClickHouse#131694 ·
メンテナーはふだん 1 日以内に返信
-
cli: `execCargoMetadata` decodes stdout per chunk, corrupting non-ASCII paths across pipe boundariesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
C-Bug S-Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bevyengine/bevy#26558 ·
メンテナーはふだん 2 日以内に返信