Is it necessary to derive codecs for nested classes in ZIO json?

16 Views Asked by At

Noob question about encoding/decoding: If I have this:

  case class Pet(name: String, numLegs: Int)
  case class Person(name: String, age: Int, pets: List[Pet])

  implicit val decoder: JsonDecoder[Person] = DeriveJsonDecoder.gen[Person]
  implicit val encoder: JsonEncoder[Person] = DeriveJsonEncoder.gen[Person]
  println( someJson.fromJson[Person] )

I get an error that there's no decoder for Pet. Do I have to define encoders/decoders for every possible nested object in a top-level class? I'm thinking .gen is a macro, so shouldn't it dive into Person and figure it out?

0

There are 0 best solutions below