Skip to content

Struct namespaces with Serde #218

@Richterrettich

Description

@Richterrettich

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnamespacesIssues related to namespaces supportserdeIssues related to mapping from Rust types to XML

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions