ticofab
ticofab

Reputation: 7717

Scala, Play: IntelliJ cannot serialize Map[String, List[String]]

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:

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

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?

Upvotes: 1

Views: 237

Answers (1)

ticofab
ticofab

Reputation: 7717

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.

Upvotes: 1

Related Questions