3

In my class, I have more than 80 attributes.

I have to do it into xml file using JAXB using the same order in class.

so please suggest me a propOrder that create automatically or some other way to give in same order as i given in class.

Note:By default i m getting output in alphabetical order

example:

Java object : order[id = 1, item = 121, qty = 10, city = QWE, ..........., addr = ASD]

excepted result : In xml file
    <order>
      <id>1</id>
      <item no>121</item no>
      <qty>10</qty>
      .
      .
      .
      .
      <addr>ASD</addr>
    </order>
Yellow Flash
  • 862
  • 2
  • 10
  • 29

2 Answers2

4

If you are creating the xml from the Java object then use

@XmlType (propOrder={"id","item",..."addr"})

A similar post talks about is and in more details. JAXB and property ordering

For additional check

If you are converting xml to Java object you should use sequence element if you are validating via xsd.

http://www.w3schools.com/schema/el_sequence.asp

Community
  • 1
  • 1
AurA
  • 12,135
  • 7
  • 46
  • 63
3

The order that you specify the fields and properties in your class is not significant. This means that when the JAXB (JSR-222) implementation introspects the class it may not see the fields/properties in the same order that you specified them in. Alphabetical order is the easiest way to offer consistent ordering. If you want to specify an order you need to use propOrder on @XmlType.

bdoughan
  • 147,609
  • 23
  • 300
  • 400