I'd like to serialize a Map[Int, Int]
using the Play Framework JSON libraries. I want something like
import play.api.libs.json._
implicit val formatIntMap = Json.format[Map[Int, Int]]
That code however gets an No unapply function found
which I think is referring to the fact that there is no extractor for Map
since it isn't a simple case class.
It will try to make a JsObject but is failing as it maps a String to a JsValue, rather than an Int to a JsValue. You need to tell it how to convert your keys into Strings.
This will turn a Map[Int, Int] containing 0 -> 123 into