简体   繁体   English

scala.Iterable [java.lang.String]没有play.api.libs.json.Format的实例。

[英]No instance of play.api.libs.json.Format is available for scala.Iterable[java.lang.String]

Trying to map a simple class using play version 2.6.2 and scala 2.11.11 尝试使用Play版本2.6.2和Scala 2.11.11映射一个简单的类

import play.api.libs.json._
import play.api.libs.json.util._
import play.api.libs.json.Reads._
import play.api.libs.json.Writes._
import play.api.libs.json.Format._
import play.api.libs.functional.syntax._

case class ObjectInfo (
    names : Iterable[String],
    info : Iterable[String]
)

object ObjectInfo {

  /**
    * Mapping to and from JSON.
    */
  implicit val documentFormatter = Json.format[ObjectInfo]

}

getting: 得到:

No instance of play.api.libs.json.Format is available for scala.Iterable[java.lang.String], scala.Iterable[java.lang.String] in the implicit scope (Hint: if declared in the same file, make sure it's declared before) 隐式范围内的scala.Iterable [java.lang.String],scala.Iterable [java.lang.String]都无法使用play.api.libs.json.Format实例(提示:如果在同一文件中声明,确保之前已声明)

I was expecting Play to automatically map these fields since they're not complex object types but simple Collection of strings. 我期望Play能够自动映射这些字段,因为它们不是复杂的对象类型而是简单的字符串集合。

You provide "too much" implicit stuff with your imports. 您在导入中提供了“太多”的隐式内容。 If you remove all imports but the first one, it will compile and do what you want. 如果删除除第一个导入以外的所有导入,它将编译并执行您想要的操作。

If you enable implicit parameter logging via the scalac option -Xlog-implicits , you will see various "ambigouity" and "diverging implicit expansion" errors. 如果通过scalac选项-Xlog-implicits启用隐式参数日志记录,则会看到各种“模糊性”和“发散的隐式扩展”错误。 The conflicting imports are import play.api.libs.json.Reads._ / import play.api.libs.json.Writes._ and import play.api.libs.json.Format._ . 发生冲突的导入是import play.api.libs.json.Reads._ / import play.api.libs.json.Writes._import play.api.libs.json.Format._ Maybe someone else can explain this conflict in more detail. 也许其他人可以更详细地解释这种冲突。

暂无
暂无

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

相关问题 对于scala.Predef.Map [java.lang.String,scala.Option [scala.Double]],没有play.api.libs.json.Format实例可用。 - No instance of play.api.libs.json.Format is available for scala.Predef.Map[java.lang.String, scala.Option[scala.Double]] No instance of play.api.libs.json.Format is available for scala.Option[java.sql.Timestamp] in the implicit scope - No instance of play.api.libs.json.Format is available for scala.Option[java.sql.Timestamp] in the implicit scope MongoDriver和Play:java.lang.NoSuchMethodError:play.api.libs.json.JsLookup - MongoDriver and Play: java.lang.NoSuchMethodError: play.api.libs.json.JsLookup Jackson JSon:无法从START_OBJECT标记中反序列化java.lang.String的实例 - Jackson JSon : Can not deserialize instance of java.lang.String out of START_OBJECT token 值 - Value <br of type java.lang.String cannot be converted to JSONObject even though the response is in JSON format 空对象引用上的java.lang.String org.json.JSONObject.getString(java.lang.String)&#39; - java.lang.String org.json.JSONObject.getString(java.lang.String)' on a null object reference Blogger JSON API错误:值非java.lang.String类型的值无法转换为JSONObject - Blogger JSON API Error: Value Not of type java.lang.String cannot be converted to JSONObject Java - 访问 JSON 元素(llegalFormatConversionException:d.=java.lang.String) - Java - Access JSON Element (llegalFormatConversionException: d !=java.lang.String) 将java.lang.String类型映射为Postgres JSON类型 - Mapping java.lang.String type to Postgres JSON Type JSON错误:java.lang.String无法转换为JSONObject - JSON error: java.lang.String cannot be converted to JSONObject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM