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

How to decode a specific enum/sealed trait subtype with discriminator #1112

Open
wants to merge 2 commits into
base: series/2.x
Choose a base branch
from

Conversation

987Nabil
Copy link
Contributor

After thinking about the suggestions made in the issue, I think they are not desirable for default behaviour.

  1. Repurposing of @jsonDiscriminator can not only lead to inconsistencies, but is unintuitive and very strange when applied to a case class that is not part of a sealed hierarchy.
  2. Deriving the codec of the subtype and reading config from the parent seems odd as well. The code DeriveJsonCodec.gen[Dog] asks very explicitly for a Dog codec, but in my opinion the Dog codec should not be aware of it being a subtype of a sealed trait here at all. This is not only more consistent, but I would argue this change would be a breaking one. A codec that might be currently derived and works well, would suddenly fail, if this is implemented and released. And wanting a codec that treats Dog just as a case class is also reasonable.

Over all, I don't see any of these solutions as a good one. The idea is somehow to fit the derivation to some personal needs. And they don't see common to me. I decided instead to add docs how to create a custom Decoder that fails when the wrong structure is found.

Another option could be to implement #689 and define the decoder by hand.

fixes #1056
/claim #1056

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

Successfully merging this pull request may close these issues.

[Feature Request] support jsonDiscriminator in case class
2 participants