码迷,mamicode.com
首页 > Web开发 > 详细

JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc

时间:2019-02-08 23:40:39      阅读:1096      评论:0      收藏:0      [点我收藏+]

标签:post   status   new   获取对象   sel   \n   col   amp   tco   

代码程序:

 

@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

标签:post   status   new   获取对象   sel   \n   col   amp   tco   

原文地址:https://www.cnblogs.com/qianjinyan/p/10356851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!