title: Json-circe can't derive encoder for subtype of sealed trait
body: <p>Why do I get error <code>could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[A$A6.this.Bar]</code>
  in the following code:</p>
  
  <pre><code>import io.circe.{Decoder, DecodingFailure, Encoder, HCursor, Json, ObjectEncoder}
  import io.circe.generic.semiauto._
  import io.circe.generic.semiauto._
  import io.circe.syntax._
  import io.circe.parser._
  
  sealed trait Foo
  object Foo {
    case class Foo1(foo1: String) extends Foo
    case class Foo2(foo2: String) extends Foo
  
  }
  
  case class Bar(foo1: Foo.Foo1)
  
  implicit lazy val FooDecoder: Decoder[Foo] = new Decoder[Foo] {
    final def apply(c: HCursor): Decoder.Result[Foo] = {
      def decode(messageType: String, payload: Json): Decoder.Result[Foo] = messageType match {
        case "Foo1" =&gt; payload.as[Foo.Foo1](deriveDecoder[Foo.Foo1])
        case "Foo2" =&gt; payload.as[Foo.Foo2](deriveDecoder[Foo.Foo2])
      }
  
      for {
        messageType &lt;- c.downField("type").as[String]
        payload &lt;- c.downField("payload").focus.toRight(DecodingFailure("payload field is not present", Nil))
        in &lt;- decode(messageType, payload)
      } yield in
    }
  }
  
  implicit lazy val barDecoder: Decoder[Bar] = deriveDecoder[Bar]
  
  parse("""
    |{ "foo1": {
    |  "type" : "Foo1",
    |    "payload": {
    |      "foo1": "bar"
    |    }
    |  }
    |}
  """.stripMargin)
    .flatMap(json =&gt; json.as[Bar])
  </code></pre>
  
  <p>It compiles with <code>case class Bar(foo1: Foo)</code>, but <code>Foo1</code> is subtype of <code>Foo</code> and I don't want to write duplicated encoder for <code>Foo1</code> and <code>Foo2</code>. How to resolve this issue?</p>