Cannot deserialize instance of `java.lang.Integer` out of START_OBJECT token解决方法

postman测试json传入

{"umaiId":"25","userApplyDetailInfos":[{"mtiTypeId":133,"uaciNum":9},{"mtiTypeId":39,"uaciNum":2}]}

报错如下:
“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]”

我看了一下代码中,接受参数的方法头是:

public String updateUserApplyDetailInfo(@RequestBody Integer umaiId, List<UserApplyDetailInfo> userApplyDetailInfos){   }

问题就出现在这里,传入的方式是json,而接收的方式不是,所以报错!
那么更改方法头:

 public String updateUserApplyDetailInfo(@RequestBody String str) {
        Integer umaiId = Integer.parseInt(JSON.parseObject(str).get("umaiId").toString());
        List<UserApplyDetailInfo> userApplyDetailInfos = JSON.parseArray(JSON.parseObject(str).getString("userApplyDetailInfos"), UserApplyDetailInfo.class);
}

用这种方法接收并且转换成所需要的对象就可以了

发布了32 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/zhuangliren/article/details/91046542