Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ktor序列化程序不是';Android Studio看不到(未找到类';用户';的序列化程序。)_Android_Android Studio_Kotlin_Serialization_Ktor - Fatal编程技术网

Ktor序列化程序不是';Android Studio看不到(未找到类';用户';的序列化程序。)

Ktor序列化程序不是';Android Studio看不到(未找到类';用户';的序列化程序。),android,android-studio,kotlin,serialization,ktor,Android,Android Studio,Kotlin,Serialization,Ktor,我正试图在我的项目中使用Ktor。我把所有的东西都写在文档中,但它不起作用 依赖项: implementation "io.ktor:ktor-client-core:1.5.4" implementation "io.ktor:ktor-client-android:1.5.4" implementation "io.ktor:ktor-client-serialization-jvm:1.5.4" HTTPClient和请求: v

我正试图在我的项目中使用Ktor。我把所有的东西都写在文档中,但它不起作用

依赖项:

implementation "io.ktor:ktor-client-core:1.5.4"
implementation "io.ktor:ktor-client-android:1.5.4"
implementation "io.ktor:ktor-client-serialization-jvm:1.5.4"
HTTPClient和请求:

val client = HttpClient {
    install(JsonFeature){
        serializer = KotlinxSerializer()
    }
    defaultRequest {
        url {
            protocol = URLProtocol.HTTPS
            host = "testtesttest.zapto.org"
        }
    }
}

suspend fun getUsersList() = client.get<User>{
    url("/users/list")
}
当我试图将JSON反序列化为对象时,它会崩溃,出现以下错误:

kotlinx.serialization.SerializationException: Serializer for class 'User' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
奇怪的是,Android studio将枚举类视为可序列化的,而数据类则不是


解决方案是添加插件

id 'kotlinx-serialization'
kotlinx.serialization.SerializationException: Serializer for class 'User' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
id 'kotlinx-serialization'