aleksey.tomin
10/14/2020, 1:12 PM@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?Joost Klitsie
10/14/2020, 1:41 PMJoost Klitsie
10/14/2020, 1:41 PMaleksey.tomin
10/14/2020, 1:44 PMrudolf.hladik
10/15/2020, 8:11 AMrudolf.hladik
10/15/2020, 8:12 AMjson.decodeFromString(serializer, bodyResponse)
aleksey.tomin
10/15/2020, 9:05 AMdecodeFromString
😄sandwwraith
10/15/2020, 6:44 PMaleksey.tomin
10/16/2020, 4:43 AM