PrimitiveSerialDescriptor
Factory to create trivial primitive descriptors. serialName must be non-blank and unique. 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