我有一个使用jax-rs的web服务休息,我的服务返回一个对象列表,但是不知道如何将自定义状态值添加到响应中,例如 结果我想打造的是以下几点:如何使用消息返回响应,jax rs
如果其确定:
{
"status": "success",
"message": "list ok!!",
"clients": [{
"name": "john",
"age": 23
},
{
"name": "john",
"age": 23
}]
}
如果是错误:
{
"status": "error",
"message": "not found records",
"clients": []
}
我休息服务:
@POST
@Path("/getById")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<Client> getById(Client id) {
try {
return Response.Ok(new ClientLogic().getById(id)).build();
//how to add status = success, and message = list! ?
} catch (Exception ex) {
return ??
// ex.getMessage() = "not found records"
//i want return json with satus = error and message from exception
}
}