当前位置:   article > 正文

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

cannot deserialize instance of `java.util.arraylist` out of value_string tok

一例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
 at [Source: (PushbackInputStream); line: 1, column: 56]

传入的 JSON 字符串是:

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

对应的类是:
public class UserPermissionParam {

    private Integer user_id;

    private List<String> permissions;

    private String role;

}

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

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

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

改用JsonArray后OK。

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/305365
推荐阅读
相关标签
  

闽ICP备14008679号