java后台接收json数据,报错com.alibaba.fastjson.JSONObject cannot be cast to xxx

时间:2024-03-01 09:08:18

  从前台接收json封装的list数据,在后台接收时一直报错,com.alibaba.fastjson.JSONObject cannot be cast to xxx,

  使用这种方式接收可以接收

 1 @RequestMapping(value = "/insertUser", method = RequestMethod.POST)
 2 public ResultT insertUser(@RequestBody Map<String,List<User>> map){
 3     List<User> userList = map.get("insertUserList");  
 4 }
 5 
 6 //前台json格式
 7 {
 8     "insertUserList": [
 9         {
10             "firstName": "Brett",
11             "lastName": "McLaughlin",
12             "email": "aaaa"
13         },
14         {
15             "firstName": "Jason",
16             "lastName": "Hunter",
17             "email": "bbbb"
18         },
19         {
20             "firstName": "Elliotte",
21             "lastName": "Harold",
22             "email": "cccc"
23         }
24     ]
25 }