【发布时间】:2013-09-24 10:00:47
【问题描述】:
我正在使用 jax rs,我想将响应创建为 json,代码:
@Produces(MediaType.APPLICATION_JSON)
public class Rest{
@GET
Path("/Test")
public RestResponse restTest(){
return new RestResponse(100,"ERROR");
}
}
@XmlRootElement()
public class RestResponse{
private Integer code;
private String status;
private Integer id;
public RestResponse(Integer code, String status){
this.code = code;
this.status = status;
}
}
我收到的回复是:{"status":"ERROR","code":100,"id":null}
如何删除 "id":null 值?
我想对外观做出回应:
{"status":"ERROR","code":100}
我需要它,因为有时 id 为 null,有时 code 为 null,我不想显示它。
【问题讨论】: