Skip to content

Deserialization doesn't process @ for attributes correctly #553

Closed
@rrichardson

Description

@rrichardson

In order to include it as an attribute in an element, I used #[serde(rename = "@xsi:type")] which causes it to serialize correctly, e.g. <MyElement xsi:type="MyType">

However, deserialization of the same blob fails because

"missing field `@xsi:type`"

Repro:

  #[derive(Clone, Debug, Default)]
  #[derive(serde::Serialize, serde::Deserialize)]
  pub struct Grantee {
      #[serde(rename = "ID")]
      #[serde(skip_serializing_if = "Option::is_none")]
      pub id: Option<ID>,
      #[serde(rename = "@xsi:type")]
      pub r#type: TypeEnum,
      #[serde(rename="@xmlns:xsi")]
      pub ns_import: Option<String>
  }

Serialization produces XML which seems correct:

<Grantee xsi:type="Group" xmlns:xsi="http://s3.amazonaws.com/doc/2006-03-01/">
   <ID>N0NX8</ID>
</Grantee>

But deserialization produces the above result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionserdeIssues 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