【发布时间】:2016-09-25 01:22:13
【问题描述】:
我想使用 Spring Boot 编写一个小而简单的 REST 服务。 下面是 REST 服务代码:
@Async
@RequestMapping(value = "/getuser", method = POST, consumes = "application/json", produces = "application/json")
public @ResponseBody Record getRecord(@RequestBody Integer userId) {
Record result = null;
// Omitted logic
return result;
}
我发送的 JSON 对象如下:
{
"userId": 3
}
这是我得到的例外:
警告 964 --- [XNIO-2 任务 7] .w.s.m.s.DefaultHandlerExceptionResolver : 无法读取 HTTP 信息: org.springframework.http.converter.HttpMessageNotReadableException: 无法读取文档:无法反序列化 java.lang.Integer out of START_OBJECT token at [Source: java.io.PushbackInputStream@12e7333c;行:1,列:1];嵌套的 例外是 com.fasterxml.jackson.databind.JsonMappingException: Can 不在 START_OBJECT 中反序列化 java.lang.Integer 的实例 [来源:java.io.PushbackInputStream@12e7333c;线:1, 列:1]
【问题讨论】:
标签: java spring spring-boot jackson