Knows Not Much
Knows Not Much

Reputation: 31576

diverging implicit expansion for type io.circe.Encoder[scala.collection.immutable.Map[Int,Any]]

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
                              ^

Upvotes: 3

Views: 2244

Answers (1)

Andriy Plokhotnyuk
Andriy Plokhotnyuk

Reputation: 7989

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.

Upvotes: 2

Related Questions