Ktor:无法解析JacksonSerializer

时间:2018-11-29 10:44:34

标签: kotlin ktor kotlin-native kotlin-multiplatform

我正在尝试在Kotlin Multiplatform项目的commonMain模块中设置ktor http客户端(如此处https://ktor.io/clients/http-client/features/json-feature.html所述),但是无法解决对它的依赖性:

    val client = HttpClient {
        install(JsonFeature) {
            serializer = JacksonSerializer()
        }
    }

Gradle版本:4.7。

这是通用模块的build.gradle:

apply plugin: 'kotlin-multiplatform'
apply plugin: 'kotlinx-serialization'

    kotlin {
        targets {
            // Change to `presets.iosArm64` to deploy the app to iPhone
            fromPreset(presets.iosX64, 'ios') {
                compilations.main.outputKinds('FRAMEWORK')
            }
        }
        sourceSets {
            commonMain.dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"

                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "io.ktor:ktor-client-json:$ktor_version"
                implementation "io.ktor:ktor-client-jackson:$ktor_version"
            }
            commonTest {
                dependencies {
                    implementation "org.jetbrains.kotlin:kotlin-test-common"
                    implementation "org.jetbrains.kotlin:kotlin-test-annotations-common"
                }
            }
            iosMain {
                dependencies {
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"

                    implementation "io.ktor:ktor-client-ios:$ktor_version"
                    implementation "io.ktor:ktor-client-core-ios:$ktor_version"
                    implementation "io.ktor:ktor-client-json-ios:$ktor_version"
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

您不能在ios上使用jackson,因为它是JVM专用的。在ios上,仅Kotlinx.serialization有效。