Here's my case
I have some json from finagle http get client :
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
could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[A] implicit val comDecoder: Decoder[SolrDoc] = deriveDecoder
```
I want to decode the JSON Object to scala case class object
Do you have any solution?
I read the issue about circe from google too.
How I solve the issue. Thanks
Is it related to this disclaimer?
@hendisantika any news on this? I am getting the same error as well.
Hi @castillobgr , I have not the updated news yet.
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]
Semi-automatic derivation won't automatically derive decoders for nested case classes. The following should work just fine:
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]
}
It also works with the real Article. Please reopen if this doesn't fix your issue.
@travisbrown I麓ve moved my comment to https://github.com/circe/circe/issues/386. This seems to me the the better place
Most helpful comment
Semi-automatic derivation won't automatically derive decoders for nested case classes. The following should work just fine:
It also works with the real
Article. Please reopen if this doesn't fix your issue.