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

时间:2022-04-27 23:12:11

I have an object of type Map[String, List[String]]. Should be easy to serialize. Indeed if I run the console in the project dir I can do:

我有一个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"]}

Which is fine. But IntelliJ (Ultimate) complains that

哪个好。但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.

even though the same import play.api.libs.json._ is there. I am quite puzzled. Any hint?

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

1 个解决方案

#1


1  

Quite lame: the issue was a (hidden) mismatch between scala.collection.Map and scala.Predef.Map (== scala.collection.immutable.Map). I wish it would have been more visible.

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

#1


1  

Quite lame: the issue was a (hidden) mismatch between scala.collection.Map and scala.Predef.Map (== scala.collection.immutable.Map). I wish it would have been more visible.

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