java.time 未使用 jackson 正确反序列化

java.time not properly deserialised using jackson

根据 here 的描述,我应该使用 JSR-310 表示而不是数字表示来序列化 ZonedDateTime 对象。但是,我得到了数字表示。可能是什么问题?

这是我配置我正在使用的映射器的方式:

object JsonFormatter {
  private val mapper = new ObjectMapper() with ScalaObjectMapper

  mapper
    .registerModule(DefaultScalaModule)
    .registerModule(new JavaTimeModule())
    .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)

  def fromJson[T](json: String)(implicit m: Manifest[T]): T = mapper.readValue[T](json.getBytes)

  def toJson(value: Any): String = mapper.writeValueAsString(value)
}

这是我得到的反序列化示例

{"from":"CityA","to":"CityB","departureAt":1554970560.000000000,"arriveAt":1554984660.000000000,"duration":{"length":65,"unit":"MINUTES","finite":true}}

对于以下情况class:

case class Stock(from: String,
                 to: String,
                 departureAt: ZonedDateTime,
                 arriveAt: ZonedDateTime,
                 duration: Duration)

显然 WRITE_DATES_AS_TIMESTAMPS 功能默认启用,所以我不得不通过添加禁用它:

mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)