ZonedDateTime与Fasterxml Jackson序列化时期毫秒



我打算使用 epoch millisecond 进行反序列化和序列化。但是,只有deserialzation有效,但未能序列化返回到正确的ZonedDateTime

ObjectMapper mapper = new ObjectMapper();
mapper.setTimeZone(TimeZone.getDefault());
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
System.out.println(mapper.writeValueAsString(ZonedDateTime.now()));  // print 1493703996728 [Expected]
System.out.println(mapper.readValue("1493703996728", ZonedDateTime.class)); // print +49303-08-07T00:52:08+08:00[Asia/Singapore] [Unexpected]

如何使该序列化获得2017-05-02T13:46:36.728+08:00[Asia/Singapore]的日期?

com.fasterxml.jackson的版本。*全部2.8.8

您还需要禁用纳秒秒以使杰克逊分析毫秒:

mapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);

相关内容

  • 没有找到相关文章

最新更新