简体   繁体   English

将隐式传递给playframework JSON读取

[英]Passing an implicit to a playframework JSON Reads

I would like to know whats the best way to pass an implicit to a Playframework Json Reader/Writer 我想知道将隐式传递给Playframework Json Reader / Writer的最佳方法是什么

http://www.playframework.com/documentation/api/2.0/scala/play/api/libs/json/Reads.html http://www.playframework.com/documentation/api/2.0/scala/play/api/libs/json/Reads.html

In other words I would like to be able to do something like : 换句话说,我希望能够执行以下操作:

def reads(json: JsValue)(implicit configuration: TenantConfiguration): JsResult[User]

But I can't do it this way since the Reads trait doesn't match 但是我无法这样做,因为Reads特质不匹配

You can't change Reads[T], it's clear. 很明显,您不能更改Reads [T]。 I would simply create my own reads function such as? 我只是创建自己的读取函数,例如?

def customReads[T](json:JsValue)(implicit reads: Reads[T], configuration: TenantConfiguration): JsResult[T] = ...

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

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