1
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时,报序列化错误