SerialDescriptor

Factory to create a new descriptor that is identical to original except that the name is equal to serialName. Should be used when you want to serialize a type as another non-primitive type. Don't use this if you want to serialize a type as a primitive value, use PrimitiveSerialDescriptor instead.

Example:

@Serializable(CustomSerializer::class)
class CustomType(val a: Int, val b: Int, val c: Int)

class CustomSerializer: KSerializer<CustomType> {
override val descriptor = SerialDescriptor("CustomType", IntArraySerializer().descriptor)

override fun serialize(encoder: Encoder, value: CustomType) {
encoder.encodeSerializableValue(IntArraySerializer(), intArrayOf(value.a, value.b, value.c))
}

override fun deserialize(decoder: Decoder): CustomType {
val array = decoder.decodeSerializableValue(IntArraySerializer())
return CustomType(array[0], array[1], array[2])
}
}