在RESTful中隐藏JSON字段
问题是,我想在restfuljson响应中隐藏在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
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 {