Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADT derivation succeeds on decoder but fails on encoder #218

Open
matthughes opened this issue Jun 23, 2020 · 2 comments
Open

ADT derivation succeeds on decoder but fails on encoder #218

matthughes opened this issue Jun 23, 2020 · 2 comments

Comments

@matthughes
Copy link

matthughes commented Jun 23, 2020

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]
}
@radusw
Copy link

radusw commented Nov 4, 2020

@matthughes You are missing an import for the implicit conversion:
import io.circe.generic.auto.exportEncoder

@matthughes
Copy link
Author

@radusw Why would I need to pull in something from circe.generic to make circe.derivation work? I thought they were two different approaches to building the macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants