这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Jackson interpretation of XMLElements not compatible with JAXB #51

@rpatrick00

Description

@rpatrick00

I have a very simple example of a class with a List member that uses polymorphism. The Java code looks like this:

@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;
  ...
}

JAXB serializes the output correctly (or at least in the way that I want it) like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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>

Jackson JAXB annotations wraps each resulting element in the list in a redundant <computers> tag like this:

<?xml version='1.1' encoding='UTF-8'?><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>

How can I eliminate the extra wrapping Jackson is doing to generate the same shape as JAXB?

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