This does not seem to work and is throwing `Serial...
# ktor
s
This does not seem to work and is throwing
Serializer for class 'ApiResponse' is not found
Copy code
@Serializable
data class ApiResponse<T>(
    val result: T? = null,
    val error: ApiError? = null
)
call.respond(ApiResponse(result = gameEngine.newGame()))
Please help. Json.encodeToString(..) works fine. ktor config:
Copy code
fun Application.mainModule() {

  install(ContentNegotiation) {
    json()
  }
  ...
}
Using ktor 1.4.1 and serialization 1.0.0
a
Have you added 
kotlin("plugin.serialization")
  into build.gradle(.kts) file? It has to be added into each 
build.gradle.kts
 file
s
I am using multiplatform project and I have only one root
build.gradle.kts
with
Copy code
plugins {
  kotlin("multiplatform") version "1.4.10"
  id("com.github.johnrengelman.shadow") version "5.2.0"
  application
  kotlin("plugin.serialization") version "1.4.10"
  id("com.adarshr.test-logger") version "2.1.1"
}
a
you have to add this into each
build.gradle.kts
file with entities
s
I have only 1 build.gradle.kts in whole project....
same thing but with normal jvm app it still doesnt work
any help?
c
CC @Aleksei Tirman [JB]
a
I’m looking for unrar 😉
@Sourabh Rawat ktor+kotlinx.serialization doesn’t work with generic classes.
s
Alexey, so why does Json.encodeToString works fine for the same. Also, how would I implement my use case of ApiResponse. Do I have to implement a custom serializer?
What I am saying is
Json.encodeToString(ApiResponse(..))
works fine.
a
Yes. It’s not a kotlinx.serialization problem. It’s a problem with ktor + kotlinx.serialization Will you create a bugreport in ktor with you code?
s
Sure. Thanks
a
I've created an issue about this problem.
🙏 1
💯 1