Matthew Olsson
05/21/2022, 2:12 AM["Bob", 24]
into class Person(val name: String, val age: Int)
. Assuming of course that I already know the array corresponds to the Person
class (in reality, my data looks more like { "person": ["Bob", 24] }
jw
05/21/2022, 2:17 AMMatthew Olsson
05/21/2022, 2:18 AMjw
05/21/2022, 2:18 AMjw
05/21/2022, 2:19 AMMatthew Olsson
05/21/2022, 2:21 AMMatthew Olsson
05/21/2022, 5:24 AMephemient
05/21/2022, 2:41 PMMatthew Olsson
05/21/2022, 2:50 PMMatthew Olsson
05/21/2022, 2:51 PMSerializable(with = ...)
, but that (obviously) overwrites the compiler-generated serializerMatthew Olsson
05/21/2022, 2:54 PMpolymorphic
I assume. If that works, then this solution is definitely much better. Thanks for improving my hack 🙂ephemient
05/21/2022, 2:56 PM@Serializable
does. but yes, it would workephemient
05/21/2022, 3:07 PMpolymorphic(EnumVariant::class) {
for (klass in EnumVariant::class.sealedSubclasses) subclass(klass)
}
if you're on JVM and include kotlin-reflect
but otherwise that lookup is something that currently can't be done at runtime on other platformsMatthew Olsson
05/21/2022, 3:08 PMCannot use 'CapturedType(out UncheckedType)' as reified type parameter
(I do have the kotlin-reflect
dependency)ephemient
05/21/2022, 3:14 PM@OptIn(InternalSerializationApi::class)
subclass(klass as KClass<EnumVariant>, klass.serializer())
but I don't think it's meant to be used that wayMatthew Olsson
05/21/2022, 3:22 PMephemient
05/21/2022, 4:38 PMephemient
05/21/2022, 4:58 PMignoreUnknownKeys
, useAlternativeNames
, etc.) which are definitely possible to re-implement but would take more effortMatthew Olsson
05/21/2022, 7:28 PM