jdk: jdk1.8 springBoot:V2.2.5.RELEASE 请求方式:POST
POST接口: @PostMapping("") public String test(@RequestBody School a){ log.info("------------------"); log.info(JSONUtil.toJsonStr(a)); return "success"; }
public class School {
private List<Student> studentList;
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> studentList) {
this.studentList = studentList;
}
}
public class Student {
private List<Teacher> teacherList;
private List<String> testList;
public List<Teacher> getTeacherList() {
return teacherList;
}
public void setTeacherList(List<Teacher> teacherList) {
this.teacherList = teacherList;
}
public List<String> getTestList() {
return testList;
}
public void setTestList(List<String> testList) {
this.testList = testList;
}
}
public class Teacher {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
请求入参: { "studentList": [ { "teacherList": [ { "name": ["ds"] } ], "testList":["d"] } ] } 输出:{"studentList":[{"teacherList":[{}]}]}
请求入参: { "studentList": [ { "teacherList": [ { "name": [ "ds", "1" ] } ], "testList": [ "d" ] } ] } 系统异常:Invalid JSON input: Cannot construct instance of
问题: 为什么入参的name属性为数组时,且size=1能够正常序列化,testList为null, 当size>1时,报序列化错误
Comment From: quaff
@chenyu9390 1. 请不要在这里使用中文,你可以借助翻译软件转化成英语 2. 这里是用来报告Spring Boot的缺陷或者改进,不是初学者提问题的地方,建议你去stackoverflow 3. 你的版本太低了,你应该先升级到官方支持版本,确定问题还存在再提交
Comment From: snicoll
@chenyu9390 Spring Boot 2.2.x is out of support so you'll need to upgrade to at least Spring Boot 2.7 first. If you're still experiencing an issue and you'd like support from us, we can reopen this issue once you've share a small sample that we can run ourselves. Please do not paste code in text like that going forward.