错误:com.fasterxml.jackson.databind.JsonMappingException:无法反序列化Entities.Student的情况下进行START_ARRAY令牌

问题描述:

的我有一个包含“学生”对象的ArrayList一个“JudoClass”对象。当我尝试创建一个学生,我得到上述错误。错误:com.fasterxml.jackson.databind.JsonMappingException:无法反序列化Entities.Student的情况下进行START_ARRAY令牌

Post方法:

@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(); 
} 

学生是所有学生的哈希映射。 (allStudents是的ArrayList,我既测试)

的Json在邮递员:

[ 
{ 
    "id": 3, 
    "username": "Mark", 
    "password": "password" 
} 
] 

当我尝试创建或编辑JudoClass我也得到这个错误。

你的方法接受一个学生作为参数

public Response createAccount(Student aStudent) { 

但是你要发送的数组。

那么你的方法应该看起来像

public Response createAccount(List<Student> aStudent) {