前言:使用POSTMAN自测代码以便前后端联调时,发送请求后,BOOM!!!服务器抛了个这样式的东西出来。
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]]
正文:这个异常信息叽里呱啦说了一堆,其实就是在说,JSON解析报错:木有办法反序列化 ArrayList 实例
由上面的异常异常信息,我们先看一下接口的入参的确是ArrayList 属实没问题
@PostMapping("/##") public RespDto<XYZ> enableSysParam(@RequestBody List<XX> XXList) { //xxx }
再看一下 POSTMAN 传的请求入参JSON串
{ "xx":[ { "configNo":"10003", "configName":"A", "value":"99" },{ "configNo":"10034", "configName":"B", "value":"7" },{ "configNo":"10080", "configName":"C", "value":"7" } ] }
很明显问题就出在这,上一个测试接口的入参格式是ObjectA<List>,所以博主直接把上次POSTMAN测试的拿来用了,可见图省事费大劲。这次的入参格式为List ,更正如下。
[ { "configNo":"10003", "configName":"A", "value":"99" },{ "configNo":"10034", "configName":"B", "value":"7" },{ "configNo":"10080", "configName":"C", "value":"7" }