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?
01/08/2023, 5:26 AM
easiest way is just to use
you can write a custom serializer that uses
(decoder as JsonDecoder).decodeJsonElement().jsonPrimitive
if you want it deserialized to your own custom type instead
01/09/2023, 9:39 AM
Is there a notion in json when it will be a string and when it will be int?