在 ktor 插件中 "Serialization" 不适用于插件 "FreeMaker"

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

好的,我是 Ktor 的新手,我正在学习它,我在这个过程中遇到的一件事是这个错误: kotlinx.serialization.SerializationException:未找到 class 'FreeMarkerContent' 的序列化程序。 将 class 标记为 @Serializable 或显式提供序列化程序

那是因为在我的代码中,我正在使用 FreeMakcerContent 并尝试对其进行序列化:

 get {
        call.respond(FreeMarkerContent("index.ftl", mapOf("articles" to articles)))
    }

我该如何解决这个问题?

好的我想我找到了解决方案,在序列化的配置中我确实定义了我需要在其中进行消毒的路线(我的 Http Api 路线),就像这样

fun Application.configureSerialization() {
routing {
    route("api"){
        install(ContentNegotiation) {
            json()
        }
    }

}

} 所以序列化只会在这条路线上工作

我遇到了同样的问题,我通过安装 FreeMarker 插件 安装 ContentNegotiation 插件之前解决了这个问题。

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"), ""))
        }
}