JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token
一例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。
更多推荐
所有评论(0)