Closed yidou120 closed 1 year ago
Attributes should be output in specific order according to @JsonPropertyOrder
, although in XML attribute order has no semantic meaning.
Do you have an example case showing different ordering?
this is pojo defined.
@JacksonXmlRootElement(localName = "person")
@Data
public class Person {
@JacksonXmlProperty(isAttribute = true)
private String email;
@JacksonXmlProperty(isAttribute = true, localName = "person_name")
private String name;
@JacksonXmlProperty(isAttribute = true)
private int age;
private Adress adress;
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "friend")
private List<Friend> friendList;
}
this is output, age attribute is front of name.
I use @JsonPropertyOrder(value = {"email, name, age"}) this annotation, it seems not useful.
Maybe try using person_name
instead of age
for the annotation? (both should work, ideally, but maybe there's something preventing use of original name before renaming).
And yes, @JsonPropertyOrder
should work.
One thing to make sure is that Lombok (since that is used I think?) does not remove any annotations on generated classes.
yes, I tried to use person_name instead of name, but order still wrong.
and lombok does not remove any annotations on generated classes.
@yidou120 Your problem is here:
I use
@JsonPropertyOrder(value = {"email, name, age"})
this annotation, it seems not useful.
where you accidentally have single String, instead of 3 Strings like so:
@JsonPropertyOrder(value = {"email", "name", "age"})
I use @JsonOrder,but attribute that use attribute is true cannot order correctly. this annotation only useful for property field.