JAXB and property ordering

自古美人都是妖i 提交于 2019-11-27 11:45:21
VIVEK PANDIAN S

It's possible using:

@XmlType (propOrder={"prop1","prop2",..."propN"})

Just uncomment the code like this:

//@XmlType(propOrder={"company", "scheme", "agreementNumber"})

This is the correct usage.

bdoughan

Note: I lead EclipseLink JAXB (MOXy)

The order in which Java reflection returns the list of fields/properties is not guaranteed. This is why JAXB implementations do not use it to determine element order.

By default JAXB provides no guaranteed ordering. However most (if not all JAXB implementations) use alphabetical ordering since it is deterministic. To guarantee this ordering you must annotate your class as follows:

@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
public class Foo {
    ...
}
Iulian Alexandru Costeiu
@XmlType(propOrder={"company", "scheme", "agreementNumber"})

It's correct, but have you tried this?

@XmlType(propOrder={"Company", "Scheme", "AgreementNumber"})
Doug

This thread is old but worth throwing how I got my properties to generate xml in the proper order and NOT using alphabetical ordering as that was undesired. One thing to note is that I am using wink and jaxb which may behave differently then other providers. Wink was very specific about what was in the propertly list. Even elements I mark as xml transient, or not decorated at all were required to be part of

@XmlRootElement(name = "Product")
@XmlType(name="",propOrder={"productName","productVersion",..."propN"})

...admittedly I don't enough of WHY it works!:)

According to this, the order of sibling XML elements is not guaranteed.

Ryan

Just add :

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"field1", "field2", ...})
gubs

In @XmlType(propOrder={"prop1", "prop2"}) you can declare only propertyName you declared in the class. You cannot declare

XMLElement name (
@XmlElement(name="Company"))

in the XmlType propOrder as mentioned by above..

Don Thomas

You have to add the propOrder and the XmlAccessType annotations to the class.

@XmlAccessorType(XmlAccessType.FIELD)

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