Java中JSon转换ArrayList遇到的异常

时间:2021-03-30 00:46:26

异常描述:

"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@1180a866; line: 1, column: 1]",


出现这种错误应该是json的格式错误;

json格式key:value

前台json传输:

[ ] 代表List,; {}表示对象

例如 List<Model>, 其中model表示一个对象 model(string,list<String>);

json格式:

[

{
"modelName":"test",
"list":[
"id",
            "xxx"
]
}]