File tree 4 files changed +68
-0
lines changed
ktor-client/ktor-client-tests
common/test/io/ktor/client/tests
jvm/src/io/ktor/client/tests/utils
4 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ kotlin.sourceSets {
59
59
api(project(" :ktor-server:ktor-server-jetty" ))
60
60
api(project(" :ktor-features:ktor-auth" ))
61
61
api(project(" :ktor-features:ktor-websockets" ))
62
+ api(project(" :ktor-features:ktor-serialization" ))
62
63
api(" ch.qos.logback:logback-classic:$logback_version " )
63
64
api(" junit:junit:$junit_version " )
64
65
api(" org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version " )
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package io.ktor.client.tests
6
+
7
+ import io.ktor.client.features.json.*
8
+ import io.ktor.client.features.json.serializer.*
9
+ import io.ktor.client.request.*
10
+ import io.ktor.client.tests.utils.*
11
+ import kotlinx.serialization.*
12
+ import kotlin.test.*
13
+
14
+ class JsonTest : ClientLoader () {
15
+ @Serializable
16
+ data class User (val name : String )
17
+
18
+ @Serializable
19
+ @Polymorphic
20
+ data class Result <T >(val message : String , val data : T )
21
+
22
+ @OptIn(ImplicitReflectionSerializer ::class , ExperimentalStdlibApi ::class )
23
+ @Test
24
+ fun testUserGenerics () = clientTests(listOf (" js" )) {
25
+ config {
26
+ install(JsonFeature ) {
27
+ serializer = KotlinxSerializer ()
28
+ }
29
+ }
30
+
31
+ test { client ->
32
+ val expected = Result <User >(" ok" , User (" hello" ))
33
+ val response = client.get<Result <User >>(" $TEST_SERVER /json/user-generic" )
34
+
35
+ assertEquals(expected, response)
36
+ }
37
+ }
38
+ }
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ internal fun Application.tests() {
34
34
buildersTest()
35
35
downloadTest()
36
36
uploadTest()
37
+ jsonTest()
37
38
38
39
routing {
39
40
post(" /echo" ) {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package io.ktor.client.tests.utils.tests
6
+
7
+ import io.ktor.application.*
8
+ import io.ktor.http.*
9
+ import io.ktor.response.*
10
+ import io.ktor.routing.*
11
+
12
+
13
+ fun Application.jsonTest () {
14
+ routing {
15
+ route(" json" ) {
16
+ get(" user-generic" ) {
17
+ call.respondText(
18
+ """
19
+ {
20
+ "message": "ok",
21
+ "data": { "name": "hello" }
22
+ }
23
+ """ .trimIndent(), contentType = ContentType .Application .Json
24
+ )
25
+ }
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments