'in ktor plugin "Serialization" don't work with plug in "FreeMaker"
ok I'm new to Ktor and I'm learning about it, one thing that I faced in this progress was this error : kotlinx.serialization.SerializationException: Serializer for class 'FreeMarkerContent' is not found. Mark the class as @Serializable or provide the serializer explicitly
and thats becouse in my code, Im using FreeMakcerContent and its trying to Serlialize it :
get {
call.respond(FreeMarkerContent("index.ftl", mapOf("articles" to articles)))
}
how can I fix this problem?
Solution 1:[1]
I faced the same problem and I fixed it by installing FreeMarker
plugin before installing ContentNegotiation
plugin.
install(FreeMarker) {
templateLoader = ClassTemplateLoader(this::class.java.classLoader, "templates")
}
install(ContentNegotiation) {
json()
}
routing {
get("/html-freemarker") {
call.respond(FreeMarkerContent("index.ftl", mapOf("name" to "Shalaga"), ""))
}
}
Solution 2:[2]
ok I think I found the solution, in the configuration of Serialization I did define the route that i need sterilization in it ( my Http Api route), something like this
fun Application.configureSerialization() {
routing {
route("api"){
install(ContentNegotiation) {
json()
}
}
}
} so the Serialization will only work in this route
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohamed Moawia |
Solution 2 | hasan foraty |