Circe deriveDecoder/deriveEncoder 找不到类型 io.circe.generic.encoding.DerivedAsObjectEncoder 的惰性隐式值
Circe deriveDecoder/deriveEncoder could not find Lazy implicit value of type io.circe.generic.encoding.DerivedAsObjectEncoder
我正在尝试为两种情况生成编码器和解码器 类:
object EventBusCases {
case class ValuationRequest(function: RequestValue = ALL_DAY_VALS, interval: RequestValue = IntraDayIntervals.MIN_5)
implicit val requestDecoder: Decoder[ValuationRequest] = deriveDecoder[ValuationRequest]
implicit val requestEncoder: Encoder[ValuationRequest] = deriveEncoder[ValuationRequest]
case class ValuationResponse(values: List[Valuation], function: RequestValue)
implicit val responseDecoder: Decoder[ValuationResponse] = deriveDecoder[ValuationResponse]
implicit val responseEncoder: Encoder[ValuationResponse] = deriveEncoder[ValuationResponse]
}
我不断收到类似这样的错误,但对于这两种情况:
could not find Lazy implicit value of type io.circe.generic.encoding.DerivedAsObjectEncoder[eventbus.eventBusCases.ValuationResponse]
我决定也尝试为这些内部的自定义 类 派生编码器和解码器,例如 "Valuation",但我在那些上得到了相同的错误。
我正在使用 Circe 0.12.3
和 Scala 2.12.8
,这些是我的 Circe 相关 Scala 依赖项:
"com.beachape" %% "enumeratum" % "1.5.14",
"com.beachape" %% "enumeratum-circe" % "1.5.22",
"io.circe" %% "circe-core" % "0.12.3",
"io.circe" %% "circe-generic" % "0.12.3",
"io.circe" %% "circe-parser" % "0.12.3"
因此,我发现实现这项工作的方法是对 ValuationRequest 和 ValuationResponse 以及其中包含的所有自定义类型实施编码器和解码器。
对于 ValuationRequest 和 ValuationResponse,我基本上将这一点添加到包含两种情况的同一个文件中 类:
object derivation {
implicit val encodeResponse: Encoder[ValuationResponse] = Encoder.instance {
case response @ ValuationResponse(_,_) => response.asJson
}
implicit val decodeResponse: Decoder[ValuationResponse] =
List[Decoder[ValuationResponse]](
Decoder[ValuationResponse].widen
).reduceLeft(_ or _)
implicit val encodeRequest: Encoder[ValuationRequest] = Encoder.instance {
case response @ ValuationRequest(_,_) => response.asJson
}
implicit val decodeRequest: Decoder[ValuationRequest] =
List[Decoder[ValuationRequest]](
Decoder[ValuationRequest].widen
).reduceLeft(_ or _)
}
我正在尝试为两种情况生成编码器和解码器 类:
object EventBusCases {
case class ValuationRequest(function: RequestValue = ALL_DAY_VALS, interval: RequestValue = IntraDayIntervals.MIN_5)
implicit val requestDecoder: Decoder[ValuationRequest] = deriveDecoder[ValuationRequest]
implicit val requestEncoder: Encoder[ValuationRequest] = deriveEncoder[ValuationRequest]
case class ValuationResponse(values: List[Valuation], function: RequestValue)
implicit val responseDecoder: Decoder[ValuationResponse] = deriveDecoder[ValuationResponse]
implicit val responseEncoder: Encoder[ValuationResponse] = deriveEncoder[ValuationResponse]
}
我不断收到类似这样的错误,但对于这两种情况:
could not find Lazy implicit value of type io.circe.generic.encoding.DerivedAsObjectEncoder[eventbus.eventBusCases.ValuationResponse]
我决定也尝试为这些内部的自定义 类 派生编码器和解码器,例如 "Valuation",但我在那些上得到了相同的错误。
我正在使用 Circe 0.12.3
和 Scala 2.12.8
,这些是我的 Circe 相关 Scala 依赖项:
"com.beachape" %% "enumeratum" % "1.5.14",
"com.beachape" %% "enumeratum-circe" % "1.5.22",
"io.circe" %% "circe-core" % "0.12.3",
"io.circe" %% "circe-generic" % "0.12.3",
"io.circe" %% "circe-parser" % "0.12.3"
因此,我发现实现这项工作的方法是对 ValuationRequest 和 ValuationResponse 以及其中包含的所有自定义类型实施编码器和解码器。
对于 ValuationRequest 和 ValuationResponse,我基本上将这一点添加到包含两种情况的同一个文件中 类:
object derivation {
implicit val encodeResponse: Encoder[ValuationResponse] = Encoder.instance {
case response @ ValuationResponse(_,_) => response.asJson
}
implicit val decodeResponse: Decoder[ValuationResponse] =
List[Decoder[ValuationResponse]](
Decoder[ValuationResponse].widen
).reduceLeft(_ or _)
implicit val encodeRequest: Encoder[ValuationRequest] = Encoder.instance {
case response @ ValuationRequest(_,_) => response.asJson
}
implicit val decodeRequest: Decoder[ValuationRequest] =
List[Decoder[ValuationRequest]](
Decoder[ValuationRequest].widen
).reduceLeft(_ or _)
}