【发布时间】:2021-04-02 23:41:38
【问题描述】:
我已经按如下方式创建了我的请求 POJO
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Notification {
@NotNull
private String clientId;
private String userId;
@NotNull
private String requestingService;
@NotNull
private String message;
@NotNull
private String messageType;
当我如下发送请求正文时,它工作正常。
{
"clientId":"9563",
"userId":"5855541",
"requestingService":"cm-dm-service",
"message":"Document Created",
"messageType":"user-msg"
}
但是当我像下面这样发送时
{
"clientId":"9563",
"userId":true,
"requestingService":"cm-dm-service",
"message":"Document Created",
"messageType":"user-msg"
}
这是我的控制器
public ResponseEntity<Status> createNotification(@RequestBody @Valid Notification notification,
BindingResult bindingResult, HttpServletRequest request) throws AppException {
预期:抛出一些错误
实际:将 userId 的 true 值转换为 jackson 的字符串。
请告诉我是否有办法实现预期行为
【问题讨论】:
-
**true**是什么? -
@burm87 已编辑。实际上是布尔类型
标签: java json spring spring-boot jackson