Hi, I’m having a problem with ktor & kotlinx s...
# serialization
r
Hi, I’m having a problem with ktor & kotlinx serialization (not sure about the chan where to post but since it seems to be a serialization issue, I’m trying here) I declared my route:
Copy code
internal fun Route.projectV1Routes(projectService: ProjectService) {
    get("/projects/hierarchies") {
        call.respondNullable(projectService.findProjectHierarchies().map { it.toHierarchyDtoV1() })
    }
}
projectService.findProjectHierarchies()
returns an object with the type
List<ProjectHierarchy>
When I try to call that endpoint, I get an error like this one:
Copy code
2023-08-22 16:10:26.599 [eventLoopGroupProxy-6-1] ERROR Application - Unhandled: GET - /api/v1/projects/hierarchies
kotlinx.serialization.SerializationException: Class 'ArrayList' is not registered for polymorphic serialization in the scope of 'List'.
Mark the base class as 'sealed' or register the serializer explicitly.
It seems weird to me that this is not natively implemented because it seems very basic. I may have missed one import but I can’t figure out how to fix this error. my build.gradle.kts:
Copy code
dependencies {
    implementation(project(":modules:app-server:domain" ))
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
    implementation("io.ktor:ktor-server-core:2.2.4")
    implementation("io.ktor:ktor-server-netty:2.2.4")
    implementation("io.ktor:ktor-server-content-negotiation:2.2.4")
    implementation("io.ktor:ktor-serialization-kotlinx-json:2.2.4")
    implementation("ch.qos.logback:logback-classic:1.4.7")

    testImplementation("io.ktor:ktor-server-test-host:2.2.4")
}
Thank you for your help
1
I found the problem: I did not add @Serializable to my dto class. The error seems to be misleading 😅