https://kotlinlang.org logo
Title
s

Sourabh Rawat

10/26/2020, 10:57 AM
This does not seem to work and is throwing
Serializer for class 'ApiResponse' is not found
@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:
fun Application.mainModule() {

  install(ContentNegotiation) {
    json()
  }
  ...
}
Using ktor 1.4.1 and serialization 1.0.0
a

aleksey.tomin

10/26/2020, 11:02 AM
Have you added 
kotlin("plugin.serialization")
  into build.gradle(.kts) file? It has to be added into each 
build.gradle.kts
 file
s

Sourabh Rawat

10/26/2020, 11:03 AM
I am using multiplatform project and I have only one root
build.gradle.kts
with
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

aleksey.tomin

10/26/2020, 11:21 AM
you have to add this into each
build.gradle.kts
file with entities
s

Sourabh Rawat

10/26/2020, 11:25 AM
I have only 1 build.gradle.kts in whole project....
same thing but with normal jvm app it still doesnt work
any help?
c

cy

10/27/2020, 7:39 PM
CC @Aleksei Tirman [JB]
a

aleksey.tomin

10/28/2020, 5:07 AM
I’m looking for unrar 😉
@Sourabh Rawat ktor+kotlinx.serialization doesn’t work with generic classes.
s

Sourabh Rawat

10/28/2020, 5:35 AM
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

aleksey.tomin

10/28/2020, 6:35 AM
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

Sourabh Rawat

10/28/2020, 6:43 AM
Sure. Thanks
a

Aleksei Tirman [JB]

10/28/2020, 8:10 AM
I've created an issue about this problem.
💯 1
:tnx: 1