小编use*_*426的帖子

JsonMappingException:无法从START_OBJECT标记中反序列化java.lang.Integer的实例

我想用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;
}
Run Code Online (Sandbox Code Playgroud)

我发送的JSON对象如下:

{
    "userId": 3
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的例外:

WARN 964 --- [XNIO-2 task-7] .wsmsDefaultHandlerExceptionResolver:无法读取HTTP消息:org.springframework.http.converter.HttpMessageNotReadableException:无法读取文档:无法从START_OBJECT反序列化java.lang.Integer的实例令牌在[来源:java.io.PushbackInputStream@12e7333c; line:1,column:1]; 嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:无法在[来源:java.io.PushbackInputStream@12e7333c;中的START_OBJECT标记中反序列化java.lang.Integer的实例.line:1,column:1]

java spring jackson spring-boot

10
推荐指数
2
解决办法
6万
查看次数

标签 统计

jackson ×1

java ×1

spring ×1

spring-boot ×1