1

I am creating Java DTO from Xml string, But the sequence of fields are not the same. For example Xml String:

<student>
            <name>Beff</name>
            <surname>Jezos</surname>
            <age>18</age>
</student>

Converted Dto is like:

<student>
            <surname>Jezos</surname>
            <age>18</age>
            <name>Beff</name>
</student>

Is there some annotation like this that lets us to put numbers of fields like:

public class Student {

   @XmlFieldSequence(place = 1)
   public String name;
   @XmlFieldSequence(place = 2)
   public String surName;
   @XmlFieldSequence(place = 3)
   public int age;

}
  • What XML (de)serializer are you using? If you're using the Jackson library then you can use https://stackoverflow.com/questions/27577701/jackson-objectmapper-specify-serialization-order-of-object-properties – kendavidson Dec 10 '21 at 20:42

1 Answers1

0

I found this annotation from javax.xml.bind.annotation.XmlType;

@XmlType(propOrder = {"name","surname","age"})
    public class Student{
       public String name;
       public String surName;
       public int age;
    }