【问题标题】:Error: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of Entities.Student out of START_ARRAY token错误:com.fasterxml.jackson.databind.JsonMappingException:无法从 START_ARRAY 令牌中反序列化 Entities.Student 的实例
【发布时间】:2017-10-12 01:24:00
【问题描述】:

我有一个“JudoClass”对象,其中包含一个“Student”对象的arrayList。当我尝试创建学生时,出现上述错误。

发布方式:

  @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 是一个数组列表,我正在测试两者)

邮递员中的Json:

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

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

【问题讨论】:

    标签: java json postman restful-architecture


    【解决方案1】:

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

    public Response createAccount(Student aStudent) {
    

    但是你正在发送一个数组。

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

    public Response createAccount(List<Student> aStudent) {
    

    【讨论】:

      猜你喜欢
      • 2017-09-10
      • 1970-01-01
      • 2020-06-16
      • 2020-09-23
      • 2016-06-05
      • 1970-01-01
      • 2016-07-30
      • 2015-03-10
      • 2019-10-25
      相关资源
      最近更新 更多