localdate反序列化java错误:com.fasterxml.jackson.databind.exc.mismatchedinputexception:应为数组或字符串

yb3bgrhw  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(239)

我无法反序列化 LocalDate :

@JsonDeserialize(using = LocalDateDeserializer.class)
  @JsonSerialize(using = LocalDateSerializer.class)
  private LocalDate dateOfBirth;

  @Test
  public void test() throws IOException {

    ObjectMapper ob = new ObjectMapper();
    ob.registerModule(new JavaTimeModule());
    ob.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    String json = "{\n"
        + "        \"year\": 2021,\n"
        + "        \"month\": \"JUNE\",\n"
        + "        \"era\": \"CE\",\n"
        + "        \"dayOfYear\": 155,\n"
        + "        \"dayOfWeek\": \"FRIDAY\",\n"
        + "        \"leapYear\": false,\n"
        + "        \"dayOfMonth\": 4,\n"
        + "        \"monthValue\": 6,\n"
        + "        \"chronology\":\n"
        + "        {\n"
        + "            \"id\": \"ISO\",\n"
        + "            \"calendarType\": \"iso8601\"\n"
        + "        }\n"
        + "    }";

    dateOfBirth =
    ob.readValue(json, LocalDate.class);

    System.out.println(dateOfBirth);

  }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题