I try to use kotlin.serialization (1.0.0) with ktor (1.4.1) and kotlin (1.4.10)
I have too classes:
@Serializable
class Holder<T> (val value: T)
@Serializable
class StringHolderDirect (val value: String)
The both work with Json directly
Json.encodeToString(StringHolderDirect(""))
Json.encodeToString(Holder(""))}
but with ktor works only the second, the first produces an error:
val client = HttpClient(CIO) {
this.install(JsonFeature) { serializer = KotlinxSerializer() }
}
<http://client.post|client.post><String>(URL) {
contentType(ContentType.Application.Json)
body = Holder("")
}
On run:
Exception in thread "main" kotlinx.serialization.SerializationException: Serializer for class 'Holder' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:91)
at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:130)
at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
at io.ktor.client.features.json.serializer.KotlinxSerializerKt.buildSerializer(KotlinxSerializer.kt:77)
What do I wrong?