简体   繁体   English

错误:com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY令牌中反序列化Entities.Student的实例

[英]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.

相关问题 com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY标记中反序列化TestAcceptanceCriteria的实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of TestAcceptanceCriteria out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException:无法反序列化START_ARRAY令牌 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY令牌中反序列化org.springframework.data.domain.Sort的实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException:无法从START_OBJECT令牌中反序列化java.util.ArrayList实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从START_ARRAY令牌中反序列化对象的实例 - com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException:无法反序列化VALUE_NUMBER_INT令牌中的java.util.ArrayList实例 - com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_NUMBER_INT token com.fasterxml.jackson.databind.exc.MismatchedInputException:无法反序列化 Object 的实例超出 START_ARRAY 令牌 - com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从 START_ARRAY 令牌中反序列化对象实例 - JAVA - com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA 引起:org.codehaus.jackson.map.JsonMappingException:无法从START_ARRAY令牌中反序列化com.model.user的实例 - Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.model.user out of START_ARRAY token com.fasterxml.jackson.databind.JsonMappingException 无法构造类的实例 - com.fasterxml.jackson.databind.JsonMappingException not able to construct instance of class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM