我正试图绕着Circe.
所以,这是我给出的模型:
object Gender extends Enumeration {
type Gender = Value
val Male, Female, Unisex, Unknown = Value
}
case class Product(id: String, gender: Gender.Value)
Run Code Online (Sandbox Code Playgroud)
我想要
a)将这个简单的例子编码为JSON字符串
val product = Product(id = "1234", gender = Gender.Female)
Run Code Online (Sandbox Code Playgroud)
b)将生成的JSON映射回Product case类.
我自己的尝试并没有让我走得太远:
object JsonProtocol {
implicit val productDecoder: Decoder[Product] = deriveDecoder
implicit val productEncoder: Encoder[Product] = deriveEncoder
}
Run Code Online (Sandbox Code Playgroud)
导致编译时错误
Error:(52, 49) could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[A]
implicit val productDecoder: Decoder[Product] = deriveDecoder
^
Run Code Online (Sandbox Code Playgroud)
我不知道为什么抛出这个异常以及解决方案看起来像什么.也许这是Enumeration类型的用法?但是,我只是在猜测.