Kieran Wallbanks
10/31/2023, 5:02 PMSerialName
of a polymorphic type? I basically want to migrate from one type to another whilst still supporting the old versionAdam S
10/31/2023, 6:39 PM@JsonNames
https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-names/
For non-JSON formats you can either write a custom Serializer (which can be a hassle).
Or, define an internal constructor property for each alternative name, make each one nullable with null
as the default value (so it's considered optional), mark each as internal, and define a public class property to expose whatever alternative isn't null using the elvis operator.Adam S
10/31/2023, 6:39 PMKieran Wallbanks
11/01/2023, 10:50 AMtype
field for polymorphic serialisation which is what I'm looking for.Kieran Wallbanks
11/01/2023, 10:51 AM{ "type": "foo" }
and { "type": "bar" }
use the same typeAdam S
11/01/2023, 4:02 PMrocketraman
11/01/2023, 4:34 PM@SerialName("Foo")
data class Foo()
@SerialName("NewFoo")
typealias NewFoo = Foo