未精简前,直接使用自己写的Msg类返回信息,返回信息如下:
{
"code": 100,
"msg": "成功",
"extend": {},
"AkcreateList": {}
}
在Msg类开头加入注解@JsonInclude(JsonInclude.Include.NON_EMPTY):
/**
* 通用的返回类(json)
* @author Administrator
*
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)//设置为空的属性不序列化
public class Msg {
//状态码,100成功,200失败
private int code;
//提示信息
private String msg;
//用户要返回给浏览器的数据
private java.util.Map<String, Object> extend = new HashMap<String, Object>();
private java.util.Map<String, Object> AkcreateList = new HashMap<String, Object>();
public static Msg success() {
Msg result = new Msg();
result.setCode(100);
result.setMsg("成功");
return result;
}
......
即可在返回Json数据时去除属性为空的属性,精简为返回以下信息:
{
"code": 100,
"msg": "成功"
}
注:@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)该方法已过时不再支持。