JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc
代码程序:
@PostMapping("selectById")
@ResponseBody
public Result selectById(@RequestBody int id) {
Result result =new Result();
List<User> list = userService.selectById(id);
if(list.size()==1){
result.setCode("000");
result.setMsg("success");
result.setData(list);
}else if(list.size()==0){
result.setCode("E01");
result.setMsg("输入的id找不到有效用户");
result.setData(null);
}else {
result.setCode("E02");
result.setMsg("输入的id找到大于1个有效用户");
result.setData(list);
}
return result;
}
请求内容:
POST http://localhost:8080/user/selectById
POST data:
{
"id":300
}
返回信息:
{
: "timestamp":"2019-02-08T14:05:17.430+0000",
: "status":400,
: "error":"Bad Request",
: "message":"JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `int` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]",
: "path":"/user/selectById"
}
用的是post的方式,传的入参是int id, 不是一个对象。
需要改成对象,然后获取对象的id
@ApiOperation(value = "根据ID查询用户的信息")
@PostMapping("selectById")
@ResponseBody
public Result selectById(@RequestBody User user) {
Result result =new Result();
List<User> list = userService.selectById(user.getId());
if(list.size()==1){
result.setCode("000");
result.setMsg("success");
result.setData(list);
}else if(list.size()==0){
result.setCode("E01");
result.setMsg("输入的id找不到有效用户");
result.setData(null);
}else {
result.setCode("E02");
result.setMsg("输入的id找到大于1个有效用户");
result.setData(list);
}
return result;
}
JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc的更多相关文章
- JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of j
异常信息如下: JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token ...
- SpringMVC接口测试异常:Can not deserialize instance of int out of START_OBJECT token
之前使用springmvc搭建了restful风格的接口服务,在使用mockmvc进行集成测试的时候出现了异常:Can not deserialize instance of int out of S ...
- HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r ...
- 记一次接口调试错误: {"timestamp":"2019-09-11T03:04:30.036+0000","status":500,"error":"Internal Server Error","message":"Could not write JSON: Object is null; nested exception is com.fasterxml.jackson
接口测试中用postman测试返回是正常的,但是使用其他人去调用就出错了,找了半天,才想起来使用了nginx,用于端口的代理转发.然后根据错误信息发现json格式的某个字段为null,结合日志中的报文 ...
- JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
在使用Postman测试Spring Boot项目接口时,接口返回JSON parse error: Cannot deserialize value of type `java.time.Local ...
- JSON parse error: Cannot deserialize value of type `java.util.Date` from String
DateTimePicker + @DateTimeFormat("yyyy-MM-dd HH:mm:ss")日期格式转换异常 最近在做的一个项目使用的日期格式是yyyy-MM-d ...
- jackson json转实体对象 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
Jackson反序列化错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field的解 ...
- JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value
问题原因所在:前端Vue传输的数据字段类型和后端实体类字段不一致. 我的实体类字段是int类型.前端传输的数据是布尔类型. 文章目录 1.后端方法 2.实体类字段 2.前端传输的数据 1.后端方法 @ ...
- jackson json转实体 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
jackson 2.2.2 由于vo中缺少json的某个字段属性引起 2种解决方法 1:vo中添加注解@JsonIgnoreProperties(ignoreUnknown = true) 2. m ...
随机推荐
- linux学习---ps、kill
一.ps 查看进程 ps 为我们提供了进程的一次性的查看,它所提供的查看结果并不动态连续的:如果想对进程时间监控,应该用 top 工具 linux上进程有5种状态: 1. 运行(正在运行或 ...
- Django框架----命名空间模式
命名空间模式 即使不同的APP使用相同的URL名称,URL的命名空间模式也可以让你唯一反转命名的URL. 举个例子: project中的urls.py from django.conf.urls im ...
- 每日linux命令学习-rpm命令
rpm命令 rpm是一款强大的Redhat软件包管理工具,可创建.安装.查询.验证.升级和卸载每个软件包,软件包是存储文件,包括需要安装的文件和名称.版本.说明等报信息. rpm默认支持7种操作模式, ...
- MySQL SELECT练习题*28
-- (1)用子查询查询员工“张小娟”所做的订单信息. SELECT * FROM order_master WHERE saler_no = ( SELECT employee_no FROM em ...
- PHP图片裁剪与缩放示例(无损裁剪图片)
<?php /* *exif_imagetype -- 判断一个图像的类型 *功能说明:函数功能是把一个图像裁剪为任意大小的图像,并保持图像不变形 *参数说明:输入 需要处理图片的 文件名,生成 ...
- Django 事物
事物 在这里指,将一些关于数据库的一系列操作,打包成一个原子性操作,意思是这一系列操作必须全部执行成功,如果,其中某个操作没有成功,那么这一系列操作都将滚回到之前没执行的状态,包括其中执行成功的某些操 ...
- VS 域名绑定IIs 调试
一排致敬老师傅:https://www.cnblogs.com/woxpp/p/5805624.html 问题: 域名www.jinhuang.com,网站的ip地域跳转出问题,需要测试. ①修改Ho ...
- MongoDB入门一
一.环境配置 1.下载MongoDB,找到Bin目录下所有的.exe文件,拷贝到G盘MongoDB(新建)下,在MongoDB下建一个data文件,用于存放数据,创建一个logs文件夹,文件夹下创建一 ...
- 程序员编程艺术:面试和算法心得-(转 July)
1.1 旋转字符串 题目描述 给定一个字符串,要求把字符串前面的若干个字符移动到字符串的尾部,如把字符串“abcdef”前面的2个字符'a'和'b'移动到字符串的尾部,使得原字符串变成字符串“cdef ...
- route 工具
route工具 route工具主要用来查看或修改内核路由表 查看内核路由表 route [-nee] 参数说明: -n:不要使用协议或主机名称,直接使用 IP 或 port number:-ee:使用 ...