Can I customize JAXB @XmlElementWrapper elements for a java.util.Map

喜夏-厌秋 提交于 2019-12-06 04:43:02

问题


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.


回答1:


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

  • http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html

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

  • https://bugs.eclipse.org/322423


来源:https://stackoverflow.com/questions/3448702/can-i-customize-jaxb-xmlelementwrapper-elements-for-a-java-util-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!