title: How to decode an ADT with circe without disambiguating objects
body: <p>Suppose I've got an ADT like this:</p>
  
  <pre><code>sealed trait Event
  
  case class Foo(i: Int) extends Event
  case class Bar(s: String) extends Event
  case class Baz(c: Char) extends Event
  case class Qux(values: List[String]) extends Event
  </code></pre>
  
  <p>The default generic derivation for a <code>Decoder[Event]</code> instance in <a href="https://github.com/circe/circe">circe</a> expects the input JSON to include a wrapper object that indicates which case class is represented:</p>
  
  <pre><code>scala&gt; import io.circe.generic.auto._, io.circe.parser.decode, io.circe.syntax._
  import io.circe.generic.auto._
  import io.circe.parser.decode
  import io.circe.syntax._
  
  scala&gt; decode[Event]("""{ "i": 1000 }""")
  res0: Either[io.circe.Error,Event] = Left(DecodingFailure(CNil, List()))
  
  scala&gt; decode[Event]("""{ "Foo": { "i": 1000 }}""")
  res1: Either[io.circe.Error,Event] = Right(Foo(1000))
  
  scala&gt; (Foo(100): Event).asJson.noSpaces
  res2: String = {"Foo":{"i":100}}
  </code></pre>
  
  <p>This behavior means that we never have to worry about ambiguities if two or more case classes have the same member names, but it's not always what we want—sometimes we know the unwrapped encoding would be unambiguous, or we want to disambiguate by specifying the order each case class should be tried, or we just don't care.</p>
  
  <p>How can I encode and decodes my <code>Event</code> ADT without the wrapper (preferably without having to write my encoders and decoders from scratch)?</p>
  
  <p>(This question comes up fairly often—see e.g. <a href="https://gitter.im/circe/circe?at=589de96e1465c46a5649c547">this discussion with Igor Mazor</a> on Gitter this morning.)</p>