首页 > 代码库 > Spring3.2中返回JSON去掉Bean中NULL值
Spring3.2中返回JSON去掉Bean中NULL值
在Spring3.2中返回Json字符串,过滤掉不需要的Bean中属性对应Json中key的value=http://www.mamicode.com/null的值,可以同过在Bean中加入注解的方式来过滤
使用jackson-all-1.8.1.jar包,在需要序列化输出Json的类上添加如***解
import org.codehaus.jackson.map.annotate.JsonSerialize; @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) public class BookMark { private String markId; private String title; private String umName; private String node; public String getMarkId() { return markId; } public void setMarkId(String markId) { this.markId = markId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getNode() { return node; } public void setNode(String node) { this.node = node; } public String getUmName() { return umName; } public void setUmName(String umName) { this.umName = umName; } }
加入注解之前
[{"umName":null,"markId":"3","title":"书签1","node":null}, {"umName":null,"markId":"4","title":"书签2","node":null}, {"umName":null,"markId":"5","title":"书签3","node":null}, {"umName":null,"markId":"6","title":"书签5","node":null}, {"umName":null,"markId":"7","title":"书签4","node":null}]
加入注解之后
[{"markId":"3","title":"书签1"},{"markId":"4","title":"书签2"}, {"markId":"5","title":"书签3"},{"markId":"6","title":"书签5"}, {"markId":"7","title":"书签4"}]
本文出自 “脚踏实地,仰望星空” 博客,请务必保留此出处http://xubcing.blog.51cto.com/3502962/1597220
Spring3.2中返回JSON去掉Bean中NULL值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。