json @JsonPropertyOrder(给字段排序)

作用

序列化时生效,将返回的json按字段排序。

例子

import com.fasterxml.jackson.annotation.JsonPropertyOrder;


@JsonPropertyOrder(value={"id","username","password"})
public class Student {
    private String id;
    private String username;
    private String password;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

}

原文出处:/show_1EF6N4bRTZ45.html