Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in ktor plugin "Serialization" don't work with plug in "FreeMaker"

Tags:

ktor

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?

like image 789
hasan foraty Avatar asked Nov 02 '25 06:11

hasan foraty


1 Answers

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"), ""))
        }
}
like image 152
Mohamed Moawia Avatar answered Nov 04 '25 18:11

Mohamed Moawia