代码程序:

@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的更多相关文章

  1. 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 ...

  2. SpringMVC接口测试异常:Can not deserialize instance of int out of START_OBJECT token

    之前使用springmvc搭建了restful风格的接口服务,在使用mockmvc进行集成测试的时候出现了异常:Can not deserialize instance of int out of S ...

  3. 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 ...

  4. 记一次接口调试错误: {"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,结合日志中的报文 ...

  5. 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 ...

  6. JSON parse error: Cannot deserialize value of type `java.util.Date` from String

    DateTimePicker + @DateTimeFormat("yyyy-MM-dd HH:mm:ss")日期格式转换异常 最近在做的一个项目使用的日期格式是yyyy-MM-d ...

  7. jackson json转实体对象 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

    Jackson反序列化错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field的解 ...

  8. JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value

    问题原因所在:前端Vue传输的数据字段类型和后端实体类字段不一致. 我的实体类字段是int类型.前端传输的数据是布尔类型. 文章目录 1.后端方法 2.实体类字段 2.前端传输的数据 1.后端方法 @ ...

  9. jackson json转实体 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

    jackson 2.2.2 由于vo中缺少json的某个字段属性引起 2种解决方法 1:vo中添加注解@JsonIgnoreProperties(ignoreUnknown = true) 2.  m ...

随机推荐

  1. 大数据学习路线:Zookeeper集群管理与选举

    大数据技术的学习,逐渐成为很多程序员的必修课,因为趋势也是因为自己的职业生涯.在各个技术社区分享交流成为很多人学习的方式,今天很荣幸给我们分享一些大数据基础知识,大家可以一起学习! 1.集群机器监控 ...

  2. TCP协议、算法和原理

    TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面.所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多收获. 关于TCP这个协议的细节,我还是推荐你 ...

  3. ELK学习笔记之F5利用EELK进行应用数据挖掘系列(2)-DNS

    0x00 概述 很多客户使用GTM/DNS为企业业务提供动态智能解析,解决应用就近性访问.优选问题.对于已经实施多数据中心双活的客户,则会使用GSLB提供双活流量调度.DNS作为企业业务访问的指路者, ...

  4. ELK学习笔记之F5-HTTP-requesting-logging logstash filter

    input { tcp { port => 514 type => 'f5-request' } } filter { if [type] == "f5-request" ...

  5. java使用wait(),notify(),notifyAll()实现等待/通知机制

    public class WaitNotify { static boolean flag=true; static Object lock=new Object(); static class Wa ...

  6. crontab命令的使用方法

    crontab命令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于"crontab"文件中,以供之后读取和执行. 在 ...

  7. encodeURI、encodeURIComponent

    encodeURI是对整个uri进行编码的,而encodeURIComponent是对uri中部分内容进行编码. 在进行url的字符串拼接时,需要进行两次encodeURI. 只进行一次encodeU ...

  8. win7搭建pyqt4开发环境

    版本 win7 64bit python2.7 https://www.python.org/ftp/python/2.7.13/python-2.7.13.amd64.msi pyqt4 https ...

  9. ReentrantLock$Sync.tryRelease java.lang.IllegalMonitorStateException

    早上一来,例行性的看主要环境的运行情况,发现有个环境中有如下异常: 17-02-28 08:13:37.368 ERROR pool-2-thread-65 com.ld.net.spider.Spi ...

  10. linux普通用户提权

    tar通配符注入. echo 'echo "chenglee ALL=(root) NOPASSWD: ALL" > /etc/sudoers' > demo.sh e ...