Skip to content
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

Handling varying structure #323

Closed
SorenHolstHansen opened this issue Sep 30, 2021 · 1 comment
Closed

Handling varying structure #323

SorenHolstHansen opened this issue Sep 30, 2021 · 1 comment
Labels
enhancement serde Issues related to mapping from Rust types to XML

Comments

@SorenHolstHansen
Copy link

SorenHolstHansen commented Sep 30, 2021

I am fetching a bunch of xml-text from an api which I want to read and deserialize. Most of the structure is quite uniform, but one part is not. That part can look like one of the three following

<member>
  <memberData>
      <p>Some text here inside a p-tag</p>
  </memberData>
</member>
<member>
  <memberData>
      Some text here not inside a p-tag
  </memberData>
</member>

or

<member>
  <memberData>
      <p>Some text here with redundant stuff after</p>
      <div>
        <img />
      </div>
  </memberData>
<member>

I have tried to model it like this because I am only interested in the text.

#[derive(Debug, Deserialize, PartialEq)]
struct MemberData {
    #[serde(rename = "$value")]
    body: String,
}

Now this works for the first two cases, but for the last one i get

Error: Custom("duplicate field `$value`")

Is there some way of handling this?

@Mingun
Copy link
Collaborator

Mingun commented May 21, 2022

Duplicate of #257

@Mingun Mingun marked this as a duplicate of #257 May 21, 2022
@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2022
@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML labels May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants