Multipart request with Retrofit @PartMap Error in Kotlin (Android)

前端 未结 2 1309
粉色の甜心
粉色の甜心 2021-02-01 19:49

If I am using this code in Java then its working fine. When I convert that code in kotlin then I got Error.

Logcat

08-20 23:46:51.003 3782-3782/

相关标签:
2条回答
  • 2021-02-01 20:29

    Add @JvmSuppressWildcards before RequestBody

    fun updateCustomerDetail(@PartMap map: Map<String, @JvmSuppressWildcards RequestBody >): Call<UpdateCustomer>
    
    0 讨论(0)
  • 2021-02-01 20:51

    Use HashMap or MutableMap instead of Map< K, out V> for the PartMap

    Alternative way that works fine for me. Mentioned by tpom6oh in Retrofi Kotlin Issue

    I think it's happening because the Map declaration is public interface Map< K, out V> and the out word makes the value type generic. You can try to use MutableMap or HashMap instead.

    @Multipart
    @POST("customer")
    fun updateCustomerDetail(@PartMap map: HashMap<String, RequestBody>): Call<UpdateCustomer>
    
    0 讨论(0)
提交回复
热议问题