码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC 中List 对象转换成Json格式 List对象中属性为NUll解决

时间:2015-10-13 01:40:13      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:springmvc      list<tree>   tree   easyui   

问题起因:今天在做一个EasyUI 同步树的时候,在SpringMVC中用 @ResponseBody标签将List<tree> 集合转换成Json数据的时候,出现一些原因。


问题描述:1、tree对象有个List<tree>属性需要为空,这个是做树用的,下级没值当然不能有null了

代码:

[{"id":1,"text":"权限管理 ","state":"closed  ","pid":-1,"children":[{"id":2,"text":"菜单管理","state":"open","pid":1,"children":null},{"id":3,"text":"角色管理","state":"open","pid":1,"children":null},{"id":4,"text":"用户管理","state":"open","pid":1,"children":null}]},{"id":5,"text":"33","state":"open","pid":-1,"children":null}]

解决方法;在实体类上使用 @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) 标签 就解决了!

加上标签后:

[{"id":1,"text":"权限管理 ","state":"closed  ","pid":-1,"children":[{"id":2,"text":"菜单管理","state":"open","pid":1},{"id":3,"text":"角色管理","state":"open","pid":1},{"id":4,"text":"用户管理","state":"open","pid":1}]},{"id":5,"text":"33","state":"open","pid":-1}]



本文出自 “一雨青尘” 博客,请务必保留此出处http://13145200724.blog.51cto.com/6263780/1702312

SpringMVC 中List 对象转换成Json格式 List对象中属性为NUll解决

标签:springmvc      list<tree>   tree   easyui   

原文地址:http://13145200724.blog.51cto.com/6263780/1702312

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!