Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotilin: Unable to pass list of enum class element #2457

Closed
antechrestos opened this issue Aug 18, 2017 · 2 comments
Closed

Kotilin: Unable to pass list of enum class element #2457

antechrestos opened this issue Aug 18, 2017 · 2 comments

Comments

@antechrestos
Copy link

Hi,

First of all thanks for your work. Your library is very helpfull for building quickly api client services.

I am currently working on version "2.2.0". I wanted to build the following service in kotlin 1.1 (List refers to kotlin collection):

interface MyService{
    @GET("/my/api/path/that/wont/work")
    fun wontWork(
           @Query("enumParameter") enumParameters: List<EnumQueryParameter>?=null)
            : Call<String>
}

// ...
    val httpClientBuilder: OkHttpClient.Builder = OkHttpClient.Builder()
    val retrofit = Retrofit.Builder()
                .baseUrl("http://somewhere.org")
                .client(httpClientBuilder.build())
                .addConverterFactory(JacksonConverterFactory.create(JacksonConfig.objectMapper))
                .build()
    val service = retrofit.create(MyService::class.java)
    service.wontWork(listOf(EnumQueryParameter.one, EnumQueryParameter.two))

Running the above code raises me an exception:

java.lang.IllegalArgumentException: Parameter type must not include a type variable or wildcard: java.util.List<? extends com.orange.datashare.api.EnumQueryParameter> (parameter #1)

From what I understood, retrofit does not accept generic types as it needs to fully know what type of object is up to handle. Yet on that point I am not asking him to handle wild card type (even though enum class is saw as a Enum<T>)

What is more surprising is it accepts the following declaration (replacing Listby MutableList)

interface MyService{
    @GET("/my/api/path/that/will/work")
    fun willWork(
            @Query("enumParameter") enumParameters: MutableList<EnumQueryParameter>?=null)
            : Call<String>
}
@JakeWharton
Copy link
Member

You can add @JvmSuppressWildcard either inside the angle brackets before the String type, or before the List. Both should work and remove the wildcard.

@antechrestos
Copy link
Author

@JakeWharton thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants