Skip to content

IllegalArgumentException: Unable to create @Body converter for class

Whenever I try to create a request with Retrofit it fails. The strange thing is that it worked before, I didn’t change anything about the code. Now months later it doesn’t work anymore. I’m getting the following error: IllegalArgumentException: Unable to create @Body converter for class apis.Config (parameter #2)

I tried changing from Gson to Moshi but it didn’t solve the problem. I also searched Stackoverflow and saw that people had similar problems but the solutions didn’t seem to work for me as they were mostly about duplicate SerializedNames which isn’t the case in my code.

API Service

interface ApiService {

        "Content-Type: application/json"
    fun getActivityInvite(@Path("voiceChannelId") voiceChannelId: String, @Body body: Config, @Header("Authorization") authorization: String): Call<ActivityInvite>


Config Class

data class Config(@SerializedName("target_application_id") val targetApplicationId: String){

    val maxAge = 86400

    val maxUses = 0

    val targetType = 2

    val temporary = false

    val validate = null


API Class

class Api {

    private val retrofit: Retrofit = Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build()
    private val apiService: ApiService = retrofit.create(
    private val props: Properties = PropertiesUtil.getProperties("")

    fun getActivityInvite(voiceId: String, activityId: String): String?{
        val config = Config(activityId)
        val request = apiService.getActivityInvite(voiceId, config, "Bot ${props.getProperty("bot_token")}")
        val response = request.execute()
        return response.body()?.getInviteUrl()



So I found the solution to the problem. Apparently the problem is caused by me using OpenJDK 16 certain things with reflection. I solved the issue by using the JVM parameters --illegal-access=permit when running the code. The solution is not optimal but it’s working.

3 People found this is helpful