1

I have the following data class:

data class Thing(
    val id: Long?,
    val title: String,
    val description: String,
)

In my Api :

@POST("doThings")
    fun createThings(
        @Query("thing") thing: Thing
    ): Call<StatusResponse>

I got the error: status":500,"error":"Internal Server Error","message":"Unexpected character ('E' (code 69))

In the spring api I made a log output and the data class object arrived as:

"Thing(id=null, title=Something, description=Something more)"

The Retrofit Builder has the GSON Converter but I guess it doesn't work properly:

Retrofit.Builder()
            .client(get())
            .baseUrl(get<Context>().getString(R.string.base_url))
            .addCallAdapterFactory(get<CoroutineCallAdapterFactory>())
            .addConverterFactory(get<GsonConverterFactory>())
            .build()

Any suggestions? Thanks

FabASP
  • 581
  • 1
  • 6
  • 20

1 Answers1

0

You are using the @Query annotation which means your Thing will be serialised as a String and passed as a query parameter in the URL.

You instead want to use the @Body annotation which will serialise the Thing object as JSON and add it to the POST body.

This answer will give you more details on how to use that annotation: https://stackoverflow.com/a/21423093/5577048

zlandorf
  • 1,100
  • 11
  • 15