File tree 4 files changed +70
-0
lines changed
ktor-client/ktor-client-tests
common/test/io/ktor/client/tests
jvm/src/io/ktor/client/tests/utils
4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ kotlin.sourceSets {
57
57
api(project(" :ktor-server:ktor-server-netty" ))
58
58
api(project(" :ktor-features:ktor-auth" ))
59
59
api(project(" :ktor-features:ktor-websockets" ))
60
+ api(project(" :ktor-features:ktor-serialization" ))
60
61
api(" ch.qos.logback:logback-classic:$logback_version " )
61
62
api(" junit:junit:$junit_version " )
62
63
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
+
16
+
17
+ @Serializable
18
+ data class User (val name : String )
19
+
20
+ @Serializable
21
+ @Polymorphic
22
+ data class Result <T >(val message : String , val data : T )
23
+
24
+ @OptIn(ImplicitReflectionSerializer ::class , ExperimentalStdlibApi ::class )
25
+ @Test
26
+ fun testUserGenerics () = clientTests(listOf (" js" )) {
27
+ config {
28
+ install(JsonFeature ) {
29
+ serializer = KotlinxSerializer ()
30
+ }
31
+ }
32
+
33
+ test { client ->
34
+ val expected = Result <User >(" ok" , User (" hello" ))
35
+ val response = client.get<Result <User >>(" $TEST_SERVER /json/user-generic" )
36
+
37
+ assertEquals(expected, response)
38
+ }
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ internal fun Application.tests() {
31
31
headersTestServer()
32
32
timeoutTest()
33
33
cookiesTest()
34
+ jsonTest()
34
35
35
36
routing {
36
37
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