jean
11/17/2021, 1:41 PMvalue
attribute as part of a json payload. That attribute can potentially be of any primitive type or null. I started with a custom serializer :
class NullableAnySerializer : KSerializer<Any?> {
override val descriptor: SerialDescriptor = // What should it be here?
override fun serialize(encoder: Encoder, value: Any?) {
when (value) {
null -> encoder.encodeNull()
is Float -> encoder.encodeFloat(value)
is Boolean -> encoder.encodeBoolean(value)
else -> throw IllegalStateException("unsupported type")
}
}
override fun deserialize(decoder: Decoder): Any? {
// What should it be here?
}
}
I’m stuck at the level of descriptor
and deserialize()
what should I use in those places?Dominaezzz
11/17/2021, 8:07 PMJsonPrimitive
?Dominaezzz
11/17/2021, 8:09 PMjean
11/18/2021, 6:50 AM