我在 Play 2.3 中有以下 JSON 阅读器:
import play.api.libs.json._
import play.api.libs.json.Reads._
val airportSearchReads: Reads[String] = (JsPath \ "search").read[String](minLength(3))
编译器给了我错误
diverging implicit expansion for type play.api.libs.json.Reads[M]
starting with method ArrayReads in trait DefaultReads
如果我使用
implicit val
我得到 ambiguous implicit values:
both value uuidReads in trait DefaultReads of type => play.api.libs.json.Reads[java.util.UUID]
and value airportSearchReads in object AirportSearch of type => play.api.libs.json.Reads[String]
match expected type play.api.libs.json.Reads[M]
我如何让它工作?
最佳答案
我得到一个不同的错误,但如果我向 minLength
添加一个显式类型参数,它对我来说很好用:
scala> val airportSearchReads: Reads[String] = (JsPath \ "search").read[String](minLength[String](3))
airportSearchReads: play.api.libs.json.Reads[String] = play.api.libs.json.Reads$$anon$8@3fee86da
我认为将其留给编译器的问题在于,作用域中有不同的隐式组合可以满足
minLength
的隐式参数列表。 .
关于json - Play Json 读取和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26684193/