当 @JsonPropertyOrder用在类上, @JsonProperty用在字段上时, JsonPropertyOrder优先级更高,?JsonProperty不会生效
@JsonPropertyOrder({"code", "name"})
class Student{
@JsonProperty(value = "name", index=10) //index按绝对值从小到大排序
private String name = "tom";
@JsonProperty(value = "code", index=20)
private String code = "1";
public static void main(String[] args) throws JsonProcessingException {
System.out.println(new ObjectMapper().writeValueAsString(new Student()));
}
}
{"code": "1", "name": "tom"}
=========================
ps: 在用JsonPropertyOrder时, 别写成了? @JsonPropertyOrder({"code, name"})
=========================