https://kotlinlang.org logo
e

eric

10/10/2017, 12:37 AM
For serialization (not deserialization), Gson's Object TypeAdapter will do this polymorphism for you at the cost of looking up in the cache the TypeAdapter for the concrete class on every call to toJson. You can also make your own delegating TypeAdapter or look at Gson's RuntimeTypeAdapterFactory.