版权声明:本文为博主原创文章,未经博主允许不得转载。 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。