diff --git a/core/commonMain/src/kotlinx/serialization/Serializers.kt b/core/commonMain/src/kotlinx/serialization/Serializers.kt index 01ea4507f..fb34224ee 100644 --- a/core/commonMain/src/kotlinx/serialization/Serializers.kt +++ b/core/commonMain/src/kotlinx/serialization/Serializers.kt @@ -283,13 +283,8 @@ private fun KSerializer.nullable(shouldBeNullable: Boolean): KSeria */ @Suppress("unused") @PublishedApi -internal fun noCompiledSerializer(forClass: String): KSerializer<*> { - throw SerializationException( - "Cannot find serializer for class $forClass.\n" + - "Make sure that this class marked with @Serializable annotation," + - "or provide serializer explicitly, or use proper SerializersModule" - ) -} +internal fun noCompiledSerializer(forClass: String): KSerializer<*> = + throw SerializationException(notRegisteredMessage(forClass)) // Used when compiler intrinsic is inserted @OptIn(ExperimentalSerializationApi::class) diff --git a/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt b/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt index f5b8e83ba..e9351853a 100644 --- a/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt +++ b/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt @@ -92,8 +92,10 @@ internal fun KClass<*>.serializerNotRegistered(): Nothing { throw SerializationException(notRegisteredMessage()) } -internal fun KClass<*>.notRegisteredMessage(): String = "Serializer for class '${simpleName}' is not found.\n" + - "Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied." +internal fun KClass<*>.notRegisteredMessage(): String = notRegisteredMessage(simpleName ?: "") + +internal fun notRegisteredMessage(className: String): String = "Serializer for class '$className' is not found.\n" + + "Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.\n" internal expect fun KClass<*>.platformSpecificSerializerNotRegistered(): Nothing