Trying to map a simple class using play version 2.6.2 and 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)
I was expecting Play to automatically map these fields since they're not complex object types but simple Collection of strings.
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. The conflicting imports areimport play.api.libs.json.Reads._
/import play.api.libs.json.Writes._
andimport play.api.libs.json.Format._
. Maybe someone else can explain this conflict in more detail.