springboot報錯_Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token


一、問題描述:

springboot框架,前台通過ajax像后台controller傳遞參數。

前台代碼:

$.ajax({
       type: "POST",//方法類型
       contentType:'application/json',
       dataType: "json",//預期服務器返回的數據類型
       url: "http://localhost:8080/saveRBD",//url
       data: JSON.stringify(list),//list是鏈表結構
       success: function (data) {
         console.log("成功");
       },
       error: function (result) {
          console.log("失敗");
       }
});

后台代碼:

//添加數據
@RequestMapping("/add")
@ResponseBody
public int addList(@RequestBody LinkedList list){
    int result = rbdService.addRBD(list);
    return result;
}

報錯:

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

二、分析原因

客戶端返回類型與接收類型不一致。

三、解決

轉換成簡單的數據類型或者自己封裝成對象來傳遞並且接收。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM