Open sam-veezoo opened 3 months ago
I think the infinite recursion comes from the fact that when deriving the Writes[Base]
we try to find if there is an existing Writes[Foo]
to use it, but that one is the very Writes[Base]
that is being derived.
I am not sure there is a better solution than requiring to upcast foo
into Base
:
- println(Json.toJson(foo))
+ println(Json.toJson(foo: Base))
Is there a way to include the discriminator even when serializing the concrete type? Concretely, I'd like to instantiate the library in this piece of code and get the same output in both println statements:
The ideomatic way to instantiate the library would only provide us with
Writes[Base]
used in the first println statement. I attempted to use generics in order to obtain suitable implicits forWrites[Foo]
andWrites[Base]
as follows:This used to work in play-json-derived-codes version 7.0.0 (together with play-json_2.12:2.8.2), however I end up with infinite recursion when using a more recent play-json-derived-codes version 10.1.0 (together with play-json_2.13:2.10.5):
Given my attempt is quite acrobatic, I am not sure whether the infinite recursion is actually a bug in the library.
Is there a way to achieve the expected result and obtain the same JSON serialization for the sealed trait as well as for the concrete case class?