[英]Error: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of Entities.Student out of START_ARRAY token
I have a 'JudoClass' object that contains an arrayList of 'Student' objects. 我有一个'JudoClass'对象,其中包含'Student'对象的arrayList。 When I try to create a student, I get the above error. 当我尝试创建学生时,出现上述错误。
Post method: 发布方法:
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/createStudent")
public Response createAccount(Student aStudent) {
students.put(aStudent.getId(), aStudent);
allStudents.add(aStudent);
System.out.print("user created with id: " + aStudent.getId());
return Response.ok(students, MediaType.APPLICATION_JSON).build();
}
students is a hash map of all the students. 学生是所有学生的哈希图。 (allStudents is an arrayList, i'm testing with both) (allStudents是一个arrayList,我正在对两者进行测试)
Json in postman: 邮递员中的Json:
[
{
"id": 3,
"username": "Mark",
"password": "password"
}
]
I also get this error when I try to create or edit a JudoClass. 当我尝试创建或编辑JudoClass时,也会出现此错误。
Your method takes one Student as parameter 您的方法以一名学生作为参数
public Response createAccount(Student aStudent) {
But you are sending an array. 但是您正在发送一个数组。
So your method should look like 所以你的方法应该像
public Response createAccount(List<Student> aStudent) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.