serialize/deserialize java 8 java.time with Jackson JSON mapper

后端 未结 17 1322
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 15:56

How do I use Jackson JSON mapper with Java 8 LocalDateTime?

org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple t

17条回答
  •  春和景丽
    2020-11-22 16:47

    There's no need to use custom serializers/deserializers here. Use jackson-modules-java8's datetime module:

    Datatype module to make Jackson recognize Java 8 Date & Time API data types (JSR-310).

    This module adds support for quite a few classes:

    • Duration
    • Instant
    • LocalDateTime
    • LocalDate
    • LocalTime
    • MonthDay
    • OffsetDateTime
    • OffsetTime
    • Period
    • Year
    • YearMonth
    • ZonedDateTime
    • ZoneId
    • ZoneOffset

提交回复
热议问题