-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-385 Add Ignored Types to JsonPlugin
- Loading branch information
Showing
7 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
ktor-client/ktor-client-plugins/ktor-client-json/common/test/JsonPluginMockTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
@file:Suppress("DEPRECATION") | ||
|
||
package io.ktor.client.plugins.json | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.call.* | ||
import io.ktor.client.engine.mock.* | ||
import io.ktor.client.request.* | ||
import io.ktor.client.utils.* | ||
import io.ktor.http.* | ||
import io.ktor.http.content.* | ||
import io.ktor.test.dispatcher.* | ||
import io.ktor.util.reflect.* | ||
import io.ktor.utils.io.core.* | ||
import kotlin.test.* | ||
|
||
class JsonPluginMockTest { | ||
|
||
@Test | ||
fun testReceiveJsonLikeString() = testSuspend { | ||
val client = HttpClient(MockEngine) { | ||
engine { | ||
addHandler { | ||
respond( | ||
"{}", | ||
headers = buildHeaders { | ||
append(HttpHeaders.ContentType, "application/json") | ||
} | ||
) | ||
} | ||
} | ||
install(JsonPlugin) { | ||
serializer = MockSerializer | ||
} | ||
} | ||
|
||
val response = client.get("/").body<String>() | ||
assertEquals("{}", response) | ||
} | ||
} | ||
|
||
object MockSerializer : JsonSerializer { | ||
override fun write(data: Any, contentType: ContentType): OutgoingContent { | ||
error("Can't serialize $data") | ||
} | ||
|
||
override fun read(type: TypeInfo, body: Input): Any { | ||
error("can't read $type") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...t/ktor-client-plugins/ktor-client-json/js/src/io/ktor/client/plugins/json/JsonPluginJs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.plugins.json | ||
|
||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf() |
11 changes: 11 additions & 0 deletions
11
...ktor-client-plugins/ktor-client-json/jvm/src/io/ktor/client/plugins/json/JsonPluginJvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.plugins.json | ||
|
||
import java.io.* | ||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf(InputStream::class) |
10 changes: 10 additions & 0 deletions
10
...-client-plugins/ktor-client-json/posix/src/io/ktor/client/plugins/json/JsonPluginPosix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.plugins.json | ||
|
||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf() |