我正在努力理解Circe。
所以,这是我收到的模型:
object Gender extends Enumeration {
type Gender = Value
val Male, Female, Unisex, Unknown = Value
}
case class Product(id: String, gender: Gender.Value)
我想将以下示例编码为 JSON
val product = Product(id = "1234", gender = Gender.Female)
b) 将生成的JSON映射回Product case类。
我的尝试并没有让我走得太远:
object JsonProtocol {
implicit val productDecoder: Decoder[Product] = deriveDecoder
implicit val productEncoder: Encoder[Product] = deriveEncoder
}
结果是编译时错误。
Error:(52, 49) could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[A]
implicit val productDecoder: Decoder[Product] = deriveDecoder
^
我不知道为什么会抛出这个异常,也不知道解决方案是什么。也许是枚举类型的使用有问题?