JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token

匿名 (未验证) 提交于 2019-12-02 20:59:24
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuzhong8809/article/details/84629614

一例JSON数组转化错误记录

错误信息如下:

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token

传入的 JSON 字符串是:

{"role":"product_engineer","user_id":"2","permissions":"[]"}

对应的类是:
public class UserPermissionParam {

}

经过一系列的排查和对比,发现是多了两个双引号,见红色部分:

{"role":"product_engineer","user_id":"2","permissions":"[]"}

用org.json 包构建这个json串的permissions部分时,没有使用jsonArray,而使用了jsonObject+StringBuild,导致了错误的串。

改用JsonArray后OK。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!