I wrote this code
import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
Map(1 -> 1, 2 -> "a").asJson.toString
but I get the following error
cmd35.sc:1: diverging implicit expansion for type
io.circe.Encoder[scala.collection.immutable.Map[Int,Any]]
starting with method encodeMapLike in object Encoder
val res35 = Map(1 -> 1, 2 -> "a").asJson.toString
^
You cannot serialize Map[Int, Any] directly with circe. If Int or String are only allowed for values then use Map[Int, Either[Int, String]] instead with a custom Encoder like here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With