当前位置:   article > 正文

JSON parse error: Cannot deserialize value of type java.util.ArrayList<SalarySecurityDto> f解决方法

json parse error: cannot deserialize value of type `java.util.arraylist

Cannot deserialize value of type java.util.ArrayList<cn.wb.oa.server.salary.dto.SalarySecurityDto> from Object value (token JsonToken.START_OBJECT)

//报错原因大概意思是类型无法转换

//这是后端接收参数的方式
@RequestMapping(value = "/reset_batch", method = RequestMethod.POST)
    public ResultResponse<Boolean> resetSalarySecurityBatch(@RequestBody List<SalarySecurityDto> salarySecurityDto) {
    }
  • 1
  • 2
  • 3
  • 4
//这是后端传的参数
[
  {
    "schoolId": 21966,
    "userId": 845072,
    "securityCode": 999999,
    "modifyUser": "林某"
  },
  {
    "schoolId": 21966,
    "userId": 778563,
    "securityCode": 999999,
    "modifyUser": "林某"
  }
]
//接口没有报错

//这是前端传的参数
[
  {
    "schoolId": "W_SCHOOLID",
    "userId": "55410",
    "modifyUser": "林某",
    "securityCode": "111111"
  },
  {
    "schoolId": "W_SCHOOLID",
    "userId": "767028",
    "modifyUser": "林某",
    "securityCode": "111111"
  },
  {
    "schoolId": "W_SCHOOLID",
    "userId": "778490",
    "modifyUser": "林某",
    "securityCode": "111111"
  }
]
//报错显示类型无法转换
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

解决方法

//更改接收参数的方式
 @RequestMapping(value = "/reset_batch", method = RequestMethod.POST)
    public ResultResponse<Boolean> resetSalarySecurityBatch(@RequestBody SalarySecurityListDto salarySecurityList) {
        List<SalarySecurityDto> salarySecurityDtolist = salarySecurityList.getSalarySecurityList();
    }
  • 1
  • 2
  • 3
  • 4
  • 5

SalarySecurityListDto实体类

public class SalarySecurityListDto implements Serializable {
    private List<SalarySecurityDto> salarySecurityList;
}
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/896719
推荐阅读
相关标签