Let's say I have following XML model:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"person",
"user"
})
@XmlRootElement(name = "CUSTOMER")
public class CUSTOMER {
@XmlElement(name = "PERSON", required = true)
protected CUSTOMER.PERSON person;
@XmlElement(name = "USER", required = true)
protected CUSTOMER.USER user;
....
....
If I rename class following conventions as:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"person",
"user"
})
@XmlRootElement(name = "CUSTOMER")
public class Customer {
....
And both elements like:
@XmlElement(name = "PERSON", required = true)
protected CUSTOMER.PERSON person;
@XmlElement(name = "USER", required = true)
protected CUSTOMER.USER user;
....
The XML from
new XmlMapper().writerWithDefaultPrettyPrinter().writeValueAsString(customer))
looks like this:
<Customer>
<id>id</id>
...
<person>
<id>id</id>
...
</person>
<user>
<id>id</id>
...
</user>
</Customer>
But I want it to look like this:
<CUSTOMER>
<id>id</id>
...
<PERSON>
<id>id</id>
...
</PERSON>
<USER>
<id>id</id>
...
</USER>
</CUSTOMER>
Am I doing something wrong? I saw that I can use @JsonProperty and it works, but only for the fields and I feel wrong using JsonProperty on an XML element. Is it okay for my model classes to be named CUSTOMER, PERSON, USER or should I rename them, and if its better to rename them should I use JsonProperty? What about the RootElement?