Scala,Play:IntelliJ无法序列化Map [String,List [String]]

时间:2016-04-12 10:12:26

标签: json scala playframework

我有一个Map [String,List [String]]类型的对象。应该很容易序列化。事实上,如果我在项目目录中运行控制台,我可以这样做:

scala> import play.api.libs.json._
import play.api.libs.json._    

scala> Json.toJson(Map("ab" -> List("yo", "yo2", "yo3"), "cd" -> List("hi", "hi1", "hi2")))
res1: play.api.libs.json.JsValue = {"ab":["yo","yo2","yo3"],"cd":["hi","hi1","hi2"]}

哪个好。但是IntelliJ(Ultimate)抱怨说

No Json serializer found for type scala.collection.Map[String,List[String]]. Try to implement an implicit Writes or Format for this type.

即使相同的导入play.api.libs.json._在那里。我很困惑。任何提示?

1 个答案:

答案 0 :(得分:1)

相当蹩脚:问题是scala.collection.Map和scala.Predef.Map(== scala.collection.immutable.Map)之间的(隐藏)不匹配。我希望它更加明显。