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

Struct namespaces with Serde #218

Open
Richterrettich opened this issue Jun 22, 2020 · 7 comments
Open

Struct namespaces with Serde #218

Richterrettich opened this issue Jun 22, 2020 · 7 comments
Labels
enhancement namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML

Comments

@Richterrettich
Copy link

Hi,
it would be really cool to have a feature to define common namespaces for structs using serde. Something like this:

#[derive(Serialize, Deserialize)]
#[namespace(F,foourn)]
struct Foo {
  id: String,
  #[serde(flatten)]
  #[namespace(B,barurn)]
  bar: Bar
}

#[derive(Serialize, Deserialize)]
struct Bar {
  name: String,
  desc: String
}

resulting in:

<F:foo xmlns:B="foourn" xmlns:F="barurn">
      <F:id>123</F:id>
      <B:name>asdf</B:name>
      <B:desc>foobar </B:desc>
</F:foo>

Background

I sometimes face (old) API's that requrie XML to be structured in a way similar to the given example. They use namespaces to distinguish between entities to form some sort of inheritance tree.
A feature like this would make interacting with these kind of API's very easy.

@mlevkov
Copy link

mlevkov commented Jun 28, 2020

I do not know how to handle this here, but I've used yaserde crate for such @Richterrettich

@tafia
Copy link
Owner

tafia commented Jul 17, 2020

This would be a nice feature indeed. Unfortunately I don't have much time but I'd be happy to integrate it if someone finds the time to do it.

@WhyNotHugo
Copy link

I'd love to see this happen, but I've no idea where to even start. What kind of macro would namespace be in order for its data to somehow be accessible in the serde (de)serialization stage?

@Mingun Mingun removed their assignment Feb 18, 2023
@meghfossa
Copy link

meghfossa commented May 26, 2023

Is there any workaround for this, or : is not supported at all. I don't mind if the workaround approach is verbose or unintuitive. Right now, I can't parse any field with : in it's name.

@WhyNotHugo
Copy link

WhyNotHugo commented May 26, 2023 via email

@Mingun
Copy link
Collaborator

Mingun commented May 26, 2023

If you don't want to write deserialization code manually, you could look at xmlserde. Support for namespaces for serde is not an easy task, unfortunately.

@dralley
Copy link
Collaborator

dralley commented Jul 26, 2023

Whoever picks this up, consider starting from #466

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement namespaces Issues related to namespaces support serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

7 participants