简体   繁体   English

Play 2.3.x中对Java8 ZonedDateTime的隐式json读写?

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

The new Play 2.4 has added out of the box support for json Writes and Reads for the new Java 8 time classes, but Play 2.3.x is still stuck with the Joda time json support only. 新打2.4增加了开箱即用支持JSON的WritesReads新的Java 8次课,但玩2.3.x版本仍然坚持只有乔达时间JSON支持。 Is there a way to get the Java 8 time json support on the 2.3.x? 有没有办法在2.3.x上获得Java 8 time json支持? How the custom Reads and Writes for ZonedDateTime would look like? 如何自定义ReadsWritesZonedDateTime会是什么样子?

You can copy the play 2.4 Writes and Reads code directly from their source code, or read it and adapt your own: 您可以复制播放2.4 WritesReads直接从他们的源代码代码,或阅读和适应你自己:

Writes: 写道:

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/702e89841fc54f5603a0d981c3488ed9883561fe/framework/src/play-json/src/main/scala/play/api/libs/json/Writes.scala

Reads: 阅读次数:

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

If you copy the files wholesale and remove the contravariant functor reads/writes, they will have no external dependencies beyond Java8 & Scala. 如果您批量复制文件并删除逆函子读/写,那么它们将不具有Java8&Scala之外的外部依赖关系。

I'm obviously not advocating this kind of copy & paste in general, but I'd don't see that it would do any harm here, as it's just a stop-gap until your project migrates to play 2.4, at which point they can be deleted. 显然,我一般不提倡这种复制和粘贴,但是我认为这样做不会造成任何伤害,因为这只是一个权宜之计,直到您的项目迁移到2.4版本为止。可以删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM