JSON parse error: Cannot deserialize value of type `java.util.ArrayList<XXX>……的解决方案

0. 报错信息

“JSON parse error: Cannot deserialize value of type java.util.ArrayList<XXX> from String value (token JsonToken.VALUE_STRING); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<com.ruoyi.sc.domain.ScHdImg> 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 {

    @Autowired
    private IScHdService scHdService;

    @Autowired
    private IScHdImgService scHdImgService;

    @PostMapping("/add")
    @ResponseBody
    public 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. 发送请求

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枯木何日可逢春

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值