Ktor:无法解析 JacksonSerializer
Posted
技术标签:
【中文标题】Ktor:无法解析 JacksonSerializer【英文标题】:Ktor: cannot resolve JacksonSerializer 【发布时间】:2019-05-01 09:47:16 【问题描述】:我正在尝试在 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】:您不能在 ios 上使用 jackson,因为它是 JVM 特定的。在 ios 上只有 Kotlinx.serialization 有效。
【讨论】:
以上是关于Ktor:无法解析 JacksonSerializer的主要内容,如果未能解决你的问题,请参考以下文章
如何使用带有 ktor 框架的 graphql-kotlin 进行字段级解析器
Kotlin/Native 无法导入 io.ktor.network.selector.ActorSelectorManager