Retrofit with kotlin, unable to create @Body

Viewed 7076

Hi i get the following error:

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

Here is my ExampleData.kt

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

}

My interface retrofit

interface UsersService {

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

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

}

function that addsUser

  override fun addUser(user: ExampleData) {
    val retrofit = Retrofit.Builder().baseUrl(baseUrl).client(httpAuthClient).build();
    val userService = retrofit.create(UsersService::class.java);
    userService.addUser(user).enqueue(callbackResponse);
}

 private val httpAuthClient: OkHttpClient
    get() {
        val okHttpClient = OkHttpClient().newBuilder().addInterceptor { chain ->
            val originalRequest = chain.request()

            val builder = originalRequest.newBuilder().header(authorizeHeader,
                    Credentials.basic(userName, password))

            val newRequest = builder.build()
            chain.proceed(newRequest)
        }.build()

        return okHttpClient


}
2 Answers
Related