Open pablf opened 1 month ago
My personal opinion is, that this is a very special solution for a probably fringe use case that is also possible to have with more generic solution that already exists. I would not merge this. Maybe @fsvehla or @jdegoes can give their opinion too.
@pablf In your example, do you really need:
implicit val dogCodec: JsonCodec[Dog] = DeriveJsonCodec.gen
or is this a copy/paste error?
@jdegoes the purpose was to have a Dog
decoder that fails without the discriminator. How would this work, if you don't create one explicitly?
@jdegoes I think so. I don't understand completely the exact needs behind the feature request. Possibly the approach with map
or transform
should be enough for the use case of @alphaho.
This is a different approach than #1112. The PR implements a
inheritDiscriminator
annotation to be used on case classes. If the parent class doesn't have ajsonDiscriminator
annotation it will throw a compilation error when deriving a codec. When there is ajsonDiscriminator
it will include this in the encoding with the name of the case class or thejsonHint
.I don't know if this is the exact use case of @alphaho, but I guess it might be encoding and decoding with different encoders for convenience when interacting between different parts of the code base. In these cases it might be easier to use something like this annotation. And this isn't a breaking change. What do you think @987Nabil? fixes #1056 /claim #1056
The final code for the example of @alphaho would be