私はjax-rsを使用してWebサービスを休息しています。私のサービスはオブジェクトのリストを返しますが、結果にカスタムステータス値を追加する方法はわかりません。例えば、 私が構築したいことは以下の通りです:返信方法返信するメッセージ、jax rs
もしそのOK:
{
"status": "error",
"message": "not found records",
"clients": []
}
私のRESTサービス:
エラーです{
"status": "success",
"message": "list ok!!",
"clients": [{
"name": "john",
"age": 23
},
{
"name": "john",
"age": 23
}]
}
場合
@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
}
}