Skip to content

Problem with polymorphic serialization, inclusion type of As.WRAPPER_OBJECT, extra tag #178

Closed
@cowtowncoder

Description

@cowtowncoder

(note: moved from FasterXML/jackson-module-jaxb-annotations#51 -- see that one for more context)

It looks like serialization includes an additional XML element level which should not be there.
As per original issue, for class like:

@XmlRootElement(name = "company")
@XmlAccessorType(XmlAccessType.FIELD)
public class Company {

  @XmlElements({
      @XmlElement(type = DesktopComputer.class, name = "desktop"),
      @XmlElement(type = LaptopComputer.class, name = "laptop")
  })
  private List computers;
  ...
}

produces XML output like

<company><computers>
    <computers>
      <desktop id="computer-1">
        <location>Bangkok</location>
      </desktop>
    </computers>
    <computers>
      <desktop id="computer-2">
        <location>Pattaya</location>
      </desktop>
    </computers>
    <computers>
      <laptop id="computer-3">
        <vendor>Apple</vendor>
      </laptop>
    </computers>
  </computers>
</company>

instead of more optimal way that JAXB serialization works:

<company>
    <computers>
        <desktop id="computer-1">
            <location>Bangkok</location>
        </desktop>
        <desktop id="computer-2">
            <location>Pattaya</location>
        </desktop>
        <laptop id="computer-3">
            <vendor>Apple</vendor>
        </laptop>
    </computers>
</company>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions