Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在RESTful中隐藏JSON字段_Json_Spring_Mongodb_Rest_Jersey - Fatal编程技术网

在RESTful中隐藏JSON字段

在RESTful中隐藏JSON字段,json,spring,mongodb,rest,jersey,Json,Spring,Mongodb,Rest,Jersey,问题是,我想在restfuljson响应中隐藏null元素(如果可能的话)。 REST控制器从Mongo数据库检索信息,因为该元素在那里不存在,所以当它们为null时,我希望忽略它们 这是我的REST控制器(暴露在运动衫中): 这就是结果: [{"id":"542c00c2ff5e0ba4ea58790d","propertyName":"property1","propertyValue":null},{"id":"542c00c2ff5e0ba4ea58790e","propertyName

问题是,我想在restfuljson响应中隐藏
null
元素(如果可能的话)。 REST控制器从Mongo数据库检索信息,因为该元素在那里不存在,所以当它们为
null
时,我希望忽略它们

这是我的REST控制器(暴露在运动衫中):

这就是结果:

[{"id":"542c00c2ff5e0ba4ea58790d","propertyName":"property1","propertyValue":null},{"id":"542c00c2ff5e0ba4ea58790e","propertyName":"property2","propertyValue":null},{"id":"542c00c2ff5e0ba4ea58790f","propertyName":"property3","propertyValue":null}]
我使用Spring数据作为持久层。我尝试了JSONIgnore注释和类似的东西,但没有任何东西适合我。 欢迎任何帮助


提前感谢。

试着这样注释它:

@JsonInclude(Include.NON_EMPTY)
public class PropertyEntity implements GenericEntity {

正如我所评论的,我试过了,但不起作用。无论如何,谢谢你的帮助。
[{"id":"542c00c2ff5e0ba4ea58790d","propertyName":"property1","propertyValue":null},{"id":"542c00c2ff5e0ba4ea58790e","propertyName":"property2","propertyValue":null},{"id":"542c00c2ff5e0ba4ea58790f","propertyName":"property3","propertyValue":null}]
@JsonInclude(Include.NON_EMPTY)
public class PropertyEntity implements GenericEntity {