当前位置:   article > 正文

错误分析:Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token_json parse error: cannot deserialize instance of `

json parse error: cannot deserialize instance of `java.lang.integer` out of

下面方法是post方法,但是参数既有json对象,又有链接携带参数

@PostMapping("/xxxx")		//post请求
//@RequestBody 表示传入的参数是一个json对象
//@RequestParam 表示传入的参数是一个链接中携带的参数
public xxxx find(@RequestBody String id , @RequestParam String name){
	//从传入的json对象中获取单个参数的value
    Integer id = Integer.parseInt(JSON.parseObject(id).get("id").toString().trim());
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

postman测试中,既要设置param,又要设置body中的json数据

在这里插入图片描述
在这里插入图片描述
如果postman传入的json,但是方法接收的是@RequestParam就会报错

“message”: “JSON parse error: Cannot deserialize instance of java.lang.Integer out of START_OBJECT token; 
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance 
of java.lang.Integer out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]”
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/305408?site
推荐阅读
相关标签
  

闽ICP备14008679号