我正在使用 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 为空,有时代码为空,我不想显示它。