Skip to content

ADT derivation succeeds on decoder but fails on encoder #218

Description

@matthughes

The following example ADT fails to derive the Encoder for Foo but can generate the Decoder. Changing this to use generic.semiauto works. This uses the latest 0.13.0-M4 release.

import io.circe._
import io.circe.derivation._

sealed trait Foo {
  def id: String
}
object Foo {
  // could not find implicit value for parameter instance: io.circe.Encoder.AsObject[Bar]
  implicit val encoder: Encoder[Foo] = deriveEncoder[Foo] 
  implicit val decoder: Decoder[Foo] = deriveDecoder[Foo]
}

final case class Bar (
    id: String
) extends Foo 
object Bar {
  implicit val encoder: Encoder[Bar] =
    deriveEncoder[Bar]
  implicit val decoder: Decoder[Bar] =
    deriveDecoder[Bar]
}

final case class Baz(
    id: String
) extends Foo 

object Baz {
  implicit val encoder: Encoder[Baz] = deriveEncoder[Baz]
  implicit val decoder: Decoder[Baz] = deriveDecoder[Baz]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions