I have the following use-case:
Each class that I'm serde using JSON4S have a field, named ID
. This ID
can be any type T <: Stringifiable
, where Stringifiable
requires your ID type to be hashed to a string. Stringifiables also have constructors that rebuilds them from a string.
I'd like to serde any Stringifiable
, for example ComplexIdentifier
to a JSON of ID: stringified_identifier
. Serialization works nicely, but unfortunately during deserialization, JSON4S is not going to use the default constructor which has only 1 string constructor. It finds the constructor, but if the identifier has a signature of case class ComplexIdentifier(whatever: String)
, it tries to extract a whatever
name from the JString(stringified_identifier)
. That fails, so MappingException
is thrown internally.
Is there any way to teach JSON4S to use the default constructor without extracting the values like this? It would be so obvious to just use the value from the JString
and construct the Stringifiable
using that.
Thanks!