Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit d4b3be9

Browse files
author
dn1345
committed
Replace gson dependency with ktor-gson
1 parent b697cc8 commit d4b3be9

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

backend/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies {
1919
testCompile "org.jsoup:jsoup:1.9.1"
2020

2121
compile "io.ktor:ktor-server-jetty:$ktor_version"
22-
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
22+
compile group: "io.ktor", name: "ktor-gson", version: "0.9.0"
2323
}
2424

2525
sourceSets {

backend/src/org/jetbrains/demo/thinkter/Application.kt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package org.jetbrains.demo.thinkter
22

3-
import com.google.gson.*
43
import org.jetbrains.demo.thinkter.dao.*
54
import io.ktor.application.*
6-
import io.ktor.content.*
75
import io.ktor.features.*
6+
import io.ktor.gson.GsonConverter
87
import io.ktor.http.*
98
import io.ktor.locations.*
10-
import io.ktor.pipeline.PipelineContext
11-
import io.ktor.request.ApplicationReceiveRequest
129
import io.ktor.response.respond
1310
import io.ktor.routing.*
1411
import io.ktor.sessions.*
15-
import org.jetbrains.demo.thinkter.model.RpcData
1612

1713
data class Session(val userId: String)
1814

@@ -49,17 +45,4 @@ fun Application.main() {
4945
login(storage, ::hash)
5046
register(storage, ::hash)
5147
}
52-
}
53-
54-
class GsonConverter(private val gson: Gson = Gson()) : ContentConverter {
55-
override suspend fun convertForSend(context: PipelineContext<Any, ApplicationCall>, contentType: ContentType, value: Any): Any? {
56-
return TextContent(gson.toJson(value), contentType.withCharset(context.call.suitableCharset()))
57-
}
58-
59-
override suspend fun convertForReceive(context: PipelineContext<ApplicationReceiveRequest, ApplicationCall>): Any? {
60-
val request = context.subject
61-
val value = request.value as? IncomingContent ?: return null
62-
val type = request.type
63-
return gson.fromJson(value.readText(), type.javaObjectType)
64-
}
6548
}

0 commit comments

Comments
 (0)