I wrote this code
import io.circe._
import io.circe.refined._
import cats.data._
import cats.implicits._
import eu.timepit.refined.auto._
final case class Translation(lang: LanguageCode, name: ProductName)
final case class Product(id: ProductId, names: List[Translation])
object Translation {
implicit val decode: Decoder[Translation] = Decoder.forProduct2("lang", "name")(Translation.apply)
implicit val encode: Encoder[Translation] = Encoder.forProduct2("lang", "name")(t => (t.lang, t.name))
}
object Product {
implicit val decode: Decoder[Product] = Decoder.forProduct2("id", "names")(Product.apply)
implicit val encode: Encoder[Product] = Encoder.forProduct2("id", "names")(p => (p.id, p.names))
}
This works fine and it compiles. but if I change my Product Type to use a cats non-empty set.
final case class Product(id: ProductId, names: NonEmptySet[Translation])
I get a compile time error
could not find implicit value for parameter decodeA1:
io.circe.Decoder[cats.data.NonEmptySet[com.abhi.models.Translation]]"
What can I do so that it auto-generates the decoder for the NonEmptySet just like it does for the List?
Looking at the circe source code it provides a
Decoder[NonEmptySet[A]]
if given aDecoder[A]
and aOrder[A]
.My guess is you're missing an implicit for
Order[Translation]
.