3

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
                              ^
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

1 Answers1

2

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.

Andriy Plokhotnyuk
  • 7,883
  • 2
  • 44
  • 68