➕➖ Byttet ut Jackson med KotlinX, la til respons
Co-authored-by: Sindre Kjelsrud <sindre.kjelsrud@nav.no> Co-authored-by: Markus A. R. Johansen <markus.aleksander.rakil.johansen@nav.no>
This commit is contained in:
parent
fdf54063c2
commit
e49bce0470
3 changed files with 9 additions and 12 deletions
|
@ -5,6 +5,8 @@ val logback_version: String by project
|
|||
plugins {
|
||||
kotlin("jvm") version "1.8.22"
|
||||
id("io.ktor.plugin") version "2.3.2"
|
||||
kotlin("plugin.serialization") version "1.8.21"
|
||||
|
||||
}
|
||||
|
||||
group = "no.nav.helse.sprik"
|
||||
|
@ -31,6 +33,4 @@ dependencies {
|
|||
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
|
||||
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
|
||||
implementation("io.ktor:ktor-serialization-jackson:$ktor_version")
|
||||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3")
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
package no.nav.helse.sprik
|
||||
|
||||
class Test (
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class Test (
|
||||
var ord: String,
|
||||
var tall: Int
|
||||
) {
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package no.nav.helse.sprik.plugins
|
||||
|
||||
import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.jackson.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.request.*
|
||||
import no.nav.helse.sprik.Test
|
||||
|
@ -17,14 +15,10 @@ fun Application.configureRouting() {
|
|||
anyHost()
|
||||
allowMethod(HttpMethod.Get)
|
||||
allowMethod(HttpMethod.Post)
|
||||
//allowHeader(HttpHeaders.AccessControlAllowOrigin)
|
||||
allowNonSimpleContentTypes = true
|
||||
}
|
||||
install(ContentNegotiation) {
|
||||
jackson {
|
||||
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
registerModule(JavaTimeModule())
|
||||
}
|
||||
json()
|
||||
}
|
||||
routing {
|
||||
get("/") {
|
||||
|
@ -33,7 +27,7 @@ fun Application.configureRouting() {
|
|||
post("/test") {
|
||||
val test = call.receive<Test>()
|
||||
println(test)
|
||||
//call.respondText(test.toString())
|
||||
call.respond(status = HttpStatusCode.Created, message = test)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue