Avatar ·

在 Kotlin 中使用 Jackson 和 Retrofit 时出现错误:No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator

大家好!我是 Kotlin 和 Android 开发的新手。我正在编写一个通过 Retrofit 和 Jackson 从服务器获取数据的应用程序。我有一个用于 API 响应的 data class: ```kotlin data class UserResponse( val id: Int, val name: String, val email: String ) ``` 以及 Retrofit 接口: ```kotlin interface ApiService { @GET("users/{id}") suspend fun getUser(@Path("id") userId: Int): UserResponse } ``` 在 `MainActivity` 中,我发起请求: ```kotlin lifecycleScope.launch { val response = apiService.getUser(1) textView.text = response.name } ``` 但应用程序崩溃并出现以下错误: ``` com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.example.app.UserResponse` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (BufferedInputStream); line: 1, column: 2] ``` 我在 `b` 中使用了以下依赖项