Reputation: 7549
I'm trying to get a Kotlin JS app working, and when consuming data from a server using this code:
val client = HttpClient {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
@Serializable
data class Entry(val start: String, val end: String)
suspend fun loadData() {
val data = client.get<List<Entry>>("http://localhost:8080/data") {
accept(ContentType.Application.Json)
}
console.log(data)
}
I get exceptions like this:
Serializer for class 'Entry' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
On Kotlin/JS explicitly declared serializer should be used for interfaces and enums without @Serializable annotation
even though the class is marked as @Serializable
.
If I change it to client.get<List<Map<String,String>>>
then I get a valid result.
What am I doing wrong?
Upvotes: 1
Views: 107
Reputation: 7549
I needed to add this to build.gradle.kts:
kotlin("plugin.serialization") version "1.4.31"
Upvotes: 1