@@ -31,13 +31,17 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
3131
3232 public final override fun serialize (encoder : Encoder , value : T ) {
3333 val actualSerializer = findPolymorphicSerializer(encoder, value)
34+ val serialPolymorphicNumberInSerializersModule = if (descriptor.useSerialPolymorphicNumbers)
35+ findSerialPolymorphicNumberOrNull(encoder, value)
36+ else
37+ null
3438 encoder.encodeStructure(descriptor) {
3539 if (descriptor.useSerialPolymorphicNumbers)
3640 encodeIntElement(
3741 descriptor,
3842 0 ,
39- // it seems not possible to cache this with the current implementation that serializers are completely separated from serializers modules
40- actualSerializer.descriptor.serialPolymorphicNumberByBaseClass.getValue(baseClass)
43+ serialPolymorphicNumberInSerializersModule
44+ ? : actualSerializer.descriptor.serialPolymorphicNumberByBaseClass.getValue(baseClass)
4145 )
4246 else
4347 encodeStringElement(descriptor, 0 , actualSerializer.descriptor.serialName)
@@ -125,6 +129,16 @@ public abstract class AbstractPolymorphicSerializer<T : Any> internal constructo
125129 value : T
126130 ): SerializationStrategy <T >? =
127131 encoder.serializersModule.getPolymorphic(baseClass, value)
132+
133+ /* *
134+ * TODO
135+ */
136+ @InternalSerializationApi
137+ public fun <T : Any > AbstractPolymorphicSerializer<T>.findSerialPolymorphicNumberOrNull (
138+ encoder : Encoder ,
139+ value : T
140+ ): Int? =
141+ encoder.serializersModule.getSerialPolymorphicNumber(baseClass, value)
128142}
129143
130144@JvmName(" throwSubtypeNotRegistered" )
0 commit comments