这是我的情况
我有一些来自 finagle http get client 的 json :
package com.hendisantika.circe
import cats.syntax.either._
import io.circe.{Decoder, Json}
import io.circe.optics.JsonPath._
import io.circe.parser._
import io.circe.generic.semiauto._
object TryCirce extends App {
val json: String = """
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"indent":"true",
"q":"content_t:circe &&\narticle_id_l:6729941",
"wt":"json"}},
"response":{"numFound":1,"start":0,"docs":[
{
"id":"comment:9404033",
"comment_id_l":9404033,
"article_id_l":6729941,
"reply_to_id_l":0,
"user_id_l":1686628,
"username_s":"uzumaki_naruto",
"email_s":"[email protected]",
"content_t":"Hello circe! I am learning about you now ",
"report_i":0,
"type_s":"comment",
"category_is":[71],
"category_ss":["JSON"],
"created_dt":"2016-05-19T02:12:01Z",
"created_ts_l":1463623921,
"is_deleted_i":0,
"country_code_s":"id",
"_version_":1534721405555310592},
{
"id":"comment:14995036",
"comment_id_l":14995036,
"article_id_l":10169921,
"reply_to_id_l":0,
"user_id_l":1148579,
"username_s":"uchiha_madara",
"email_s":"[email protected]",
"content_t":"Hai circe, You are very handsome.",
"report_i":0,
"type_s":"comment",
"category_is":[71],
"category_ss":["LIB"],
"created_dt":"2017-01-10T01:28:51Z",
"created_ts_l":1484011731,
"is_deleted_i":0,
"country_code_s":"id",
"_version_":1556099467469389824}]
}}"""
implicit val comDecoder: Decoder[SolrDoc] = deriveDecoder[SolrDoc]
val obj = decode[SolrDoc](json2) match {
case Left(failure) => println("Oh no --> " + failure)
case Right(com) => println("OK Success")
println(com)
}
}
case class SolrDoc(response: Option[SolrResponse])
case class SolrResponse(
numFound:Int,
start : Int,
docs : List[Article]
)
case class Article(
id: String,
comment_id_l: Option[Long],
article_id_l: Option[Long],
reply_to_id_l: Option[Long],
user_id_l: Option[Long],
username_s: Option[String],
email_s: Option[String],
content_t: String,
report_i: Option[Int],
type_s: Option[String],
category_is: List[Int],
category_ss: List[String],
created_dt: Option[String],
created_ts_l: Option[Long],
is_deleted_i: Option[Int],
country_code_s: Option[String],
version: Option[Long]
)
//Error:(43, 47) could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[A]
implicit val comDecoder: Decoder[SolrDoc] = deriveDecoder
// Error:(43, 47) not enough arguments for method deriveDecoder: (implicit decode: shapeless.Lazy[io.circe.generic.decoding.DerivedDecoder[A]])io.circe.Decoder[A].
Unspecified value parameter decode.
implicit val comDecoder: Decoder[SolrDoc] = deriveDecoder
找不到 io.circe.generic.decoding.DerivedDecoder[A] 类型的惰性隐式值
```
我想将 JSON 对象解码为 scala 案例类对象
你有什么解决办法吗?
我也从谷歌阅读了关于 circe 的问题。
我如何解决这个问题。 谢谢
它与此免责声明有关吗?
@hendisantika有这方面的消息吗? 我也遇到了同样的错误。
嗨@castillobgr ,我还没有更新的消息。
case class SolrDoc(response: SolrResponse)
case class SolrResponse(docs: Seq[Article])
case class Article()
object TryCirce extends App {
import io.circe.generic.semiauto.deriveDecoder
implicit val comDecoder: Decoder[SolrDoc] = deriveDecoder[SolrDoc]
}
could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[models.foo.SolrDoc]
[error] implicit val comDecoder: Decoder[SolrDoc] = deriveDecoder[SolrDoc]
半自动派生不会自动派生嵌套案例类的解码器。 以下应该可以正常工作:
case class SolrDoc(response: SolrResponse)
case class SolrResponse(docs: Seq[Article])
case class Article()
object TryCirce extends App {
import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
implicit val decodeArticle: Decoder[Article] = deriveDecoder[Article]
implicit val decodeSolrResponse: Decoder[SolrResponse] = deriveDecoder[SolrResponse]
implicit val decodeSolrDoc: Decoder[SolrDoc] = deriveDecoder[SolrDoc]
}
它也适用于真正的Article
。 如果这不能解决您的问题,请重新打开。
@travisbrown我已将我的评论移至https://github.com/circe/circe/issues/386。 这在我看来是更好的地方
最有用的评论
半自动派生不会自动派生嵌套案例类的解码器。 以下应该可以正常工作:
它也适用于真正的
Article
。 如果这不能解决您的问题,请重新打开。