0. 报错信息

“JSON parse error: Cannot deserialize value of type java.util.ArrayList from String value (token JsonToken.VALUE_STRING); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList from String value (token JsonToken.VALUE_STRING)\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 6, column: 13] (through reference chain: com.ruoyi.wx.vo.WxHdVo[“yhzp”])”

1. 报错原因分析

WxHdVo.java

public class WxHdVo implements Serializable {/** 上报人 */private String sbr;/** 隐患地点 */private String yhdd;/** 隐患部位 */private String yhbw;/** 隐患描述 */private String yhms;/** 隐患照片 */private List<ScHdImg> yhzp;}

WxHdController.java

@Controller@RequestMapping("/wx/hd")public class WxHdController {@Autowiredprivate IScHdService scHdService;@Autowiredprivate IScHdImgService scHdImgService;@PostMapping("/add")@ResponseBodypublic String addHdFromWx(@RequestBody WxHdVo wxHdVo) {ScHd scHd = new ScHd(wxHdVo.getSbr(), wxHdVo.getYhdd(), wxHdVo.getYhbw(), wxHdVo.getYhms());scHdService.insertScHd(scHd);Long scHdId = scHd.getId();for (ScHdImg hdImg : wxHdVo.getYhzp()) {scHdImgService.insertScHdImg(new ScHdImg(scHdId, hdImg.getUrl(), new Date(), "1"));}return "success";}}

发送请求的Body

{"sbr": "xinglibao","yhdd": "绿地世纪城","yhbw": "一号消防通道","yhms": "消防通道被堵塞","yhzp": "[{'url': 'haha'}, {'url': 'heihei'}]"}

在百度搜索后发现是自己的 json 写错了,应将"yhzp": "[{'url': 'haha'}, {'url': 'heihei'}]"修改为"yhzp": [{"url": "haha"}, {"url": "heihei"}]
在百度搜索后发现是自己的 json 写错了,应将"yhzp": "[{'url': 'haha'}, {'url': 'heihei'}]"修改为"yhzp": [{"url": "haha"}, {"url": "heihei"}]
在百度搜索后发现是自己的 json 写错了,应将"yhzp": "[{'url': 'haha'}, {'url': 'heihei'}]"修改为"yhzp": [{"url": "haha"}, {"url": "heihei"}]

2. 发送请求