title: scala circe encoders/decoders for an abstract class with case classes
body: <p>I want to save a collection of FieldMapping classes as a json string -</p>
  <pre><code>abstract class Field {
    def clazz: Class[_]
  
    def name: String
  }
  
  case class StringField(name: String) extends Field {
    override def clazz: Class[_] = classOf[String]
  }
  
  case class DateField(name: String) extends Field {
    override def clazz: Class[_] = classOf[Date]
  }
  </code></pre>
  <p>... etc - full code here:
  <a href="https://github.com/alexeyOnGitHub/scala-typesafe/blob/master/src/main/scala/com/example/model/Field.scala" rel="nofollow noreferrer">https://github.com/alexeyOnGitHub/scala-typesafe/blob/master/src/main/scala/com/example/model/Field.scala</a></p>
  <p>Circe code:</p>
  <pre><code>import com.example.model.{DateField, Field, FieldMapping, StringField}
  import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
  import io.circe.{Decoder, Encoder}
  
  object CirceBoilerplateForConfigs {
    implicit val fieldDecoder: Decoder[StringField] = deriveDecoder[StringField]
    implicit val fieldEncoder: Encoder[StringField] = deriveEncoder[StringField]
  
    implicit val dateDecoder: Decoder[DateField] = deriveDecoder[DateField]
    implicit val dateEncoder: Encoder[DateField] = deriveEncoder[DateField]
  
    implicit val fooDecoder: Decoder[FieldMapping] = deriveDecoder[FieldMapping]
    implicit val fooEncoder: Encoder[FieldMapping] = deriveEncoder[FieldMapping]
  }
  </code></pre>
  <blockquote>
  <p>Error:(14, 65) could not find Lazy implicit value of type
  io.circe.generic.decoding.DerivedDecoder[com.example.model.FieldMapping]
  implicit val fooDecoder: Decoder[FieldMapping] =
  deriveDecoder[FieldMapping] Error:(14, 65)</p>
  <p>not enough arguments for method deriveDecoder: (implicit decode:
  shapeless.Lazy[io.circe.generic.decoding.DerivedDecoder[com.example.model.FieldMapping]])io.circe.Decoder[com.example.model.FieldMapping].
  Unspecified value parameter decode.   implicit val fooDecoder:
  Decoder[FieldMapping] = deriveDecoder[FieldMapping] Error:(15, 65)</p>
  <p>could not find Lazy implicit value of type
  io.circe.generic.encoding.DerivedObjectEncoder[com.example.model.FieldMapping]
  implicit val fooEncoder: Encoder[FieldMapping] =
  deriveEncoder[FieldMapping] Error:(15, 65)</p>
  <p>not enough arguments for
  method deriveEncoder: (implicit encode:
  shapeless.Lazy[io.circe.generic.encoding.DerivedObjectEncoder[com.example.model.FieldMapping]])io.circe.ObjectEncoder[com.example.model.FieldMapping].
  Unspecified value parameter encode.   implicit val fooEncoder:
  Encoder[FieldMapping] = deriveEncoder[FieldMapping]</p>
  </blockquote>