All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.kr.jadekim.jext.ktor.module.ContentNegotiationModule.kt Maven / Gradle / Ivy

There is a newer version: 2.1.4
Show newest version
package kr.jadekim.jext.ktor.module

import com.google.gson.Gson
import io.ktor.http.*
import io.ktor.serialization.gson.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*

object ContentNegotiationModule : KtorModuleFactory {

    class Configuration : KtorModuleConfiguration {

        var configure: ContentNegotiationConfig.() -> Unit = {
            register(ContentType.Application.Json, GsonConverter())
        }

        fun gson(gson: Gson) {
            configure = {
                register(ContentType.Application.Json, GsonConverter(gson))
            }
        }
    }

    override fun create(config: Configuration): KtorModule = ktorModule {
        install(ContentNegotiation, config.configure)
    }

    override fun createDefaultConfiguration(): Configuration = Configuration()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy