I have two classes:
@XmlSeeAlso(ListType.class)
public class Type {
private int id;
public int getId() {
return id;
}
@XmlAttribute
public void setId(int id) {
this.id = id;
}
}
@XmlRootElement
public class ListType extends Type {
private String name;
private String namespace;
public String getName() {
return name;
}
@XmlAttribute
public void setName(String name) {
this.name = name;
}
public String getNamespace() {
return namespace;
}
@XmlAttribute
public void setNamespace(String namespace) {
this.namespace = namespace;
}
}
And I make marshalling:
ListType listType = new ListType();
listType.setId(123);
listType.setName("Name");
listType.setNamespace("Namespace");
JAXBContext jaxbContext = JAXBContext.newInstance(UserType.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(listType, System.out);
Finally, I get XML
like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<listUserType name="Name" namespace="Namespace" id="123"/>
All is well, just tell me, how can I specify the order of the attributes in my XML
?
I want them to go in this order:
<listType id="123" name="Name" namespace="Namespace" />
This is very necessary for solving my task. Thank you