jackson中序列化为Json中注解的使用

@JsonSerialize(include =  JsonSerialize.Inclusion.NON_NULL)
//json序列化时,如果是null的对象,key会消失
public class PicUploadResult {
    //上传是否成功的判断标识,0-成功,1-失败
    private Integer error;

    private String url;

    private String message;

    @JsonIgnore
    //使之不在json序列化结果当中
    private String width;

    @JsonIgnore
    private String height;

    public PicUploadResult(){

    }

    public Integer getError() {
        return error;
    }

    public void setError(Integer error) {
        this.error = error;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getWidth() {
        return width;
    }

    public void setWidth(String width) {
        this.width = width;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }
}

猜你喜欢

转载自blog.csdn.net/renwendaojian/article/details/79990309