Error: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of Entities.Student out of START_ARRAY token

Error: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of Entities.Student out of START_ARRAY token

我有一个 'JudoClass' 对象,其中包含 'Student' 个对象的数组列表。当我尝试创建学生时,出现上述错误。

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

students 是所有学生的哈希映射。 (allStudents 是一个 arrayList,我正在测试两者)

Json 在邮递员中:

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

我在尝试创建或编辑 JudoClass 时也遇到此错误。

你的方法需要一个学生作为参数

public Response createAccount(Student aStudent) {

但是你发送的是数组。

所以你的方法应该是这样的

public Response createAccount(List<Student> aStudent) {