4

I'm trying to learn to use Map with Jaxb. I did this:

@XmlElementWrapper(name = "phoneNumbers", nillable = true)
private Map<String, PhoneNumber> phoneNumbers;

and the result was:

 <xs:element nillable="true" name="phoneNumbers">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="key" minOccurs="0" type="xs:string"/>
              <xs:element name="value" minOccurs="0" type="PhoneNumberType"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

Is there any way to change the "entry","key","value" element names?

I've tried to use @XmlElements, @XmlElement but I just got errors.

Cajunluke
  • 3,103
  • 28
  • 28
Cristiano
  • 1,414
  • 15
  • 22
  • also check out this answer https://stackoverflow.com/questions/28718112/xsd-to-java-specify-to-use-a-java-hashmap – MMAdams Oct 31 '17 at 18:42

1 Answers1

2

You will need to use an XmlAdapter if you want finer control over the XML representation of a Map property. For more details see:

I have entered an enhancement request to handle this in the MOXy JAXB implementation:

bdoughan
  • 147,609
  • 23
  • 300
  • 400