How do I write a polymorphic serializer for two pr...
# serialization
o
How do I write a polymorphic serializer for two primitive types? I am trying to write an SDK for an API, and there are responses that can either be an int or a string. Is it possible to make a polymorphic serializer, that will serialize and deserialize API calls?
e
easiest way is just to use
JsonElement
you can write a custom serializer that uses
(decoder as JsonDecoder).decodeJsonElement().jsonPrimitive
if you want it deserialized to your own custom type instead
e
Is there a notion in json when it will be a string and when it will be int?