3

我写了这段代码

import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
Map(1 -> 1, 2 -> "a").asJson.toString

但我收到以下错误

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
                              ^
4

1 回答 1

2

您不能Map[Int, Any]直接使用 circe 进行序列化。如果IntString仅允许用于值,则使用此处Map[Int, Either[Int, String]]自定义代替。Encoder

于 2018-01-22T18:01:02.757 回答