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

Generic.extras.auto/semiauto doesn't take override codecs, but rather deriving from scratch? #991

Closed
ChengGit opened this issue Oct 18, 2018 · 2 comments

Comments

@ChengGit
Copy link

Hi,

I am using io.circe.generic.extras.deriveEnumerationDecoder for my adt (sample code)

sealed trait Org
object Org {
  case object Github extends Org {
    implicit val decoder: Decoder[Github] = <decode it into a JString of "github">
  }
  case object GItlab extends Org {
    implicit val decoder: Decoder[Gitlab]  = <decode it into a JString of "gitlab">
  }

  implicit val decoder: Decoder[Org] = deriveEnumerationDecoder[Org]

I found out that deriveEnumerationDecoder ignored my custom decoders, but rather creating new ones for my adts.

I noticed this because it actually docode my case object Github into a JString of "Github" instead of "github".

Do you have any suggestions to let generic-extras to take my custom codecs in scope?
Thanks in advance!

@ChengGit
Copy link
Author

My current workaround is to stick my logic into io.circe.generic.extras.deriveEnumerationDecoder's prepare method making sure I got a all lower case JString.
Could you correct me if I did wrong, or point me a better way please?

@travisbrown
Copy link
Member

@ChengGit deriveEnumerationDecoder is really only intended for the simple case where you have a bunch of case objects and want to decode them by name—unlike deriveDecoder, it doesn't respect custom decoders. You might be able to do something like this by having your custom decoders be EnumerationDecoder instances, but I'm not sure whether even that would work, and if it did it still wouldn't really be a supported use case.

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