Android 使用kotlin进行改装,无法创建@Body

Android 使用kotlin进行改装,无法创建@Body,android,kotlin,retrofit2,Android,Kotlin,Retrofit2,您好,我发现以下错误: java.lang.IllegalArgumentException: Unable to create @Body converter for class com.jr.app.models.ExampleData (parameter #1) 这是我的ExampleData.kt data class ExampleData(val id: String, val firstName: String,

您好,我发现以下错误:

 java.lang.IllegalArgumentException: Unable to create @Body converter for class com.jr.app.models.ExampleData (parameter #1)
这是我的ExampleData.kt

data class ExampleData(val id: String,
                   val firstName: String,
                   val secondName: String,
                   val profilImages: String,
                   val info: String) {

}
我的界面改造

interface UsersService {

@GET("/usersProfile")
fun getAllUsers(): Call<List<ExampleData>>

@POST("/usersProfile")
fun addUser(@Body exampleData: ExampleData): Call<ResponseBody>

}

我相信这与Kotlin无关,而是与您的改装配置和数据类ExampleData有关


改型不知道如何将ExampleData实例序列化为JSON。创建改造客户端实例时,需要添加特定的转换器工厂(有关详细信息,请参见方法)。

将渐变依赖项添加到项目中:

compile 'com.squareup.retrofit2:converter-gson:VERSION_OF_RETROFIT'
生成改装实例时,请添加以下行:

.addConverterFactory(GsonConverterFactory.create())
在项目建筑中,改装对象将如下所示:

val retrofit = Retrofit.Builder()
    .baseUrl(baseUrl)
    .client(httpAuthClient)
    .addConverterFactory(GsonConverterFactory.create())
    .build()
val retrofit = Retrofit.Builder()
    .baseUrl(baseUrl)
    .client(httpAuthClient)
    .addConverterFactory(GsonConverterFactory.create())
    .build()