json - Play Json 读取和字符串

标签 json scala playframework playframework-2.0 playframework-json

我在 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/

相关文章:

scala - 将 Enumeratee 转换为 Future[List] Scala

java - 实体未找到异常 : Bean has been deleted - lazy loading failed

javascript - 正确的 JSON 格式

javascript - 我如何在没有库的情况下构建 NodeJS Websocket 服务器

scala - 在 Scala 中指定 HashMap 的大小

scala - 如何在 "exec"内使 Gatling 测试失败?

scala - 为什么sortByKey的 Spark 这么慢?他们有其他选择吗?

java - 使用 org.json.JSONObject 解析 JSON 中的转义字符;

php - POSTMAN chrome 应用程序发布的意外 '<' 错误

java - Play 框架中存在 oneToMany 关系的 JPA 错误