Skip to content

Using xmlns with no prefix for some nodes and including empty nodes #210

@RedChops

Description

@RedChops

I'm currently trying to interface with a very unruly SOAP service. Most of the time it doesn't care about the default serialization method where the namespaces are defined to prefixes, but I've found at least one body part where the service is particularly picky. This service expects a node like:

<findBusinessPartyRequest xmlns="http://test.example">
  <Administrators>
    <string>SEN</string>
  </Administrators>
  <EmployeeNumber/>
  <Employer/>
  <EmployerName/>
  <LastName/>
  <FirstName>Silver</FirstName>
  <Username/>
  <SSN/>
  <EmployerSpecifiedID/>
</findBusinessPartyRequest>

Where all nodes have to be present, even if empty, otherwise the service throws a 500 error.

My struct is defined like

    #[yaserde(prefix = "par1", namespaces = {"par1" = "http://test.example"}, rename = "FindBusinessPartyParticipantRequest")]
    pub struct FindBusinessPartyParticipantRequest {
        #[yaserde(prefix = "par1", rename = "Administrators")]
        pub administrators: Option<mod_par1::ArrayOfString>,
        #[yaserde(prefix = "par1", rename = "EmployeeNumber")]
        pub employee_number: Option<String>,
        #[yaserde(prefix = "par1", rename = "Employer")]
        pub employer: Option<String>,
        #[yaserde(prefix = "par1", rename = "EmployerName")]
        pub employer_name: Option<String>,
        #[yaserde(prefix = "par1", rename = "LastName")]
        pub last_name: Option<String>,
        #[yaserde(prefix = "par1", rename = "FirstName")]
        pub first_name: Option<String>,
        #[yaserde(prefix = "par1", rename = "Username")]
        pub username: Option<String>,
        #[yaserde(prefix = "par1", rename = "SSN")]
        pub ssn: Option<String>,
        #[yaserde(prefix = "par1", rename = "EmployerSpecifiedID")]
        pub employer_specified_id: Option<String>,
    }

When I serialize this struct with only like one attribute defined, I get back

<par1:findBusinessPartyRequest xmlns:par1="http://test.example">
        <par1:Administrators>
          <string>SEN</string>
        </par1:Administrators>
        <par1:FirstName>Example</par1:FirstName>
      </par1:findBusinessPartyRequest>

This service will not process the request with the par1 prefix (or any prefix really). If I remove the prefixes and send the request by hand, I'll get back a 500 error because of the missing nodes.

Is there a way to have the serializer serialize this struct to match the expected output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions