PrimitiveSerialDescriptor
Factory to create a trivial primitive descriptors. Primitive descriptors should be used when the serialized form of the data has a primitive form, for example:
object LongAsStringSerializer : KSerializer<Long> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("kotlinx.serialization.LongAsStringSerializer", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: Long) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): Long {
return decoder.decodeString().toLong()
}
}
Content copied to clipboard