1

在发现 circe 并尝试将其实现到我的游戏应用程序中后,我发现了以下代码...

implicit val TimestampFormat : Encoder[Timestamp] with Decoder[Timestamp] = new Encoder[Timestamp] with Decoder[Timestamp] {
    override def apply(a: Timestamp): Json = Encoder.encodeLong.apply(a.getTime)
    override def apply(c: HCursor): Result[Timestamp] = Decoder.decodeLong.map(s => new Timestamp(s)).apply(c)
}

问题是apply方法返回Json,似乎没有办法将Circe JSON转换为Plays JsValue.....

如何使用 circe 返回 JsValues 或使用 play 将 circe Json 转换为 play JsValue?

4

1 回答 1

2

解决了,对不起,我在语法上使用了循环播放错误。代替

 Ok(Json.obj("data" -> CaseClass.asJson))

它应该只是......

Ok(CaseClass.asJson)
于 2017-11-25T05:41:07.247 回答