Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ktor client using KxS throws unhelpful error when trying to decode non-serializable class boxed in a generic container #4675

Open
Kantis opened this issue Feb 13, 2025 · 0 comments

Comments

@Kantis
Copy link

Kantis commented Feb 13, 2025

Given that I make any request that tries to decode something to a List<T>, where T is not serializable, Ktor-client will generate an error like this:

kotlinx.serialization.SerializationException: Serializer for class 'List' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

	at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:90)
	at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:299)
	at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
	at io.ktor.serialization.kotlinx.SerializerLookupKt.serializerForTypeInfo(SerializerLookup.kt:32)
	at io.ktor.serialization.kotlinx.KotlinxSerializationConverter.deserialize(KotlinxSerializationConverter.kt:66)
	at io.ktor.serialization.ContentConverterKt$deserialize$$inlined$map$1$2.emit(Emitters.kt:51)

Adding @Serializable to T fixed this in my case.

It's very frustrating and throws the user in the wrong direction. It seems to apply to all boxed types. For instance

data class Foo(val bar: Int)

@Serializable
data class Box<out T>(val value: T)

fun main() {
    client.get("").body<Box<Foo>>()
}

Will generate a similar error statingkotlinx.serialization.SerializationException: Serializer for class 'Box' is not found.
Once again, making Foo serializable would fix this


Ktor version: 3.1.0
KxS version: 1.8.0
Kotlin version: 2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant