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

Question: How to deserialize arbitrary tag #320

Closed
thorstenhater opened this issue Sep 12, 2021 · 1 comment
Closed

Question: How to deserialize arbitrary tag #320

thorstenhater opened this issue Sep 12, 2021 · 1 comment
Labels
serde Issues related to mapping from Rust types to XML

Comments

@thorstenhater
Copy link

I have a question and I hope this is right channel to ask. I am trying to deserialize a data format based
on XML using serde, which essentially boils down to

<root>
  <kind name="A" />
  <item kind="A">
    ...
  </item>
  <kind name="B" />
  <B>
    ...
  </B>
</root>

Note how the B tag can be used a shorthand for item kind="B".
I have a working implemention for the non-shorthand part that looks like this

// These have more inner structure, omitted for brevity
#[deriving(Deserialize)]
struct Kind { ... }
#[deriving(Deserialize)]
struct Item { ... }

#[deriving(Deserialize)]
enum RootBody {
   Item(Item),
   Kind(Kind),
}

#[deriving(Deserialize)]
struct Root {
  #[serde(rename="$value")]
  body: Vec<RootBody>,
}

However, how to capture the short-hand feature? Using the pattern from the
JSON examples

#[deriving(Deserialize)]
struct Root {
  #[serde(rename="$value")]
  body: Vec<RootBody>,
  #[serde(flatten)]
  unknown: Map<String, Value>
}

fails with Custom("missing field $value")'. I have also tried deserialize-enum-str and
had no success.

@Mingun Mingun added the serde Issues related to mapping from Rust types to XML label May 21, 2022
@Mingun
Copy link
Collaborator

Mingun commented May 21, 2022

Duplicate of #326

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

No branches or pull requests

2 participants