我正在使用 spring
创建一个 rest
服务,并希望提供一个 json
响应:
@RequestMapping(value = "/test",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public MyResponse content() {
return rsp;
}
MyResponse
可能包含 null
值,不应在 JSON
响应中返回这些值(应删除这些参数)。
@XmlRootElement
class MyResponse {
}
这可能吗?
最佳答案
试试这个:
@JsonInclude(JsonInclude.Include.NON_NULL)
class MyResponse {
...
}
您需要更新您的依赖项并导入它:
import com.fasterxml.jackson.annotation.JsonInclude;
关于java - 如何删除 json rest 响应中的空参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31476516/