隐式 json 为播放 2 中的 Java8 ZonedDateTime 写入和读取。3.x?

Implicit json Writes and Reads for Java8 ZonedDateTime in Play 2.3.x?

新的 Play 2.4 为新的 Java 8 时间 类 添加了对 json WritesReads 的开箱即用支持,但是Play 2.3.x 仍然停留在 Joda time json 支持上。有没有办法在 2.3.x 上获得 Java 8 次 json 支持? ZonedDateTime 的自定义 ReadsWrites 会是什么样子?

您可以直接从他们的源代码中复制 play 2.4 WritesReads 代码,或者阅读并改编您自己的代码:

写:

https://github.com/playframework/playframework/blob/702e89841fc54f5603a0d981c3488ed9883561fe/framework/src/play-json/src/main/scala/play/api/libs/json/Writes.scala

阅读:

https://github.com/playframework/playframework/blob/cde65d987b6cf3c307dfab8269b87a65c5e84575/framework/src/play-json/src/main/scala/play/api/libs/json/Reads.scala

如果您批量复制文件并删除逆变函子 reads/writes,它们将没有 Java8 和 Scala 之外的外部依赖。

我显然一般不提倡这种复制和粘贴,但我认为它不会对这里造成任何伤害,因为它只是一个权宜之计,直到你的项目迁移到 play 2.4 , 此时可以删除它们。