retrofit icon indicating copy to clipboard operation
retrofit copied to clipboard

java.lang.IllegalArgumentException: Parameter type must not include a type variable or wildcard: java.util.List<MyModel> (parameter #5) for method ApiService.myRequest

Open hackaprende opened this issue 6 months ago • 1 comments

I am getting this error when trying to send a list of objects in the body of my post request:

java.lang.IllegalArgumentException: Parameter type must not include a type variable or wildcard: java.util.List<MyModel> (parameter #5) for method ApiService.myRequest

The request is like this:

@POST(MY_URL)
suspend fun makeRequest(@Body myList: List<MyModel>): MyResponse

The error is still present on version com.squareup.retrofit2:retrofit:2.11.0

The solution for now is adding @JvmSuppressWildcards

This fixes the issue but makes the code less readable and more complex to understand

A solution example for others who have this problem:

@POST(MY_URL)
@JvmSuppressWildcards
suspend fun makeRequest(@Body myList: List<MyModel>): MyResponse

hackaprende avatar Jul 25 '24 19:07 hackaprende