【发布时间】:2019-09-30 09:34:37
【问题描述】:
所以问题是这样的,对于我的所有REST API 端点,我的RESPONSE Body 中应该始终存在 3 个字段,例如:
{
"status": "SUCCESS",
"message": "A list of a recent post",
"data" : [LIST OF POSTS]
}
或
{
"status" : "NOT_AUTHORIZED",
"message": "User does not have previledge to access this resource",
"errors": ["User does not have Admin access"]
}
所以你可以明白,我希望这个消息状态错误或数据字段出现在我的 REST API 的所有响应中。
【问题讨论】:
-
您可以在 POJO 中使用类似 @JsonInclude(JsonInclude.Include.NON_NULL) 的内容。这样您的响应中只能包含非空值。
-
但这不是我要问的。我想要一个适用于我所有 API 端点的响应模板。其中有“消息”、“状态”、“错误”(如果有)或“数据”(如果有)
标签: java spring-boot jersey-2.0