0

Retrofit 2.6.

 @GET("/event")
    suspend fun getEvents(@Query("orgn") base: Int, @Query("event") quote: Int): Response<List<Event>>

In service:

import retrofit2.Response

 suspend fun getEvents(
            orgn: Int,
            event: Int,
            isCustomtHandle: Boolean = false
        ): Response<*> {
           return waitressCallRestClient.getEvents(orgn, event)
        }

and in my ViewModel:

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope

 viewModelScope.launch(Dispatchers.Main) {
            val response = TransportService.getEvents(100, 200)
            if (response.isSuccessful) { 
                val eventList: List<Event> = response.body() as List<Event>

As you can see I must cast to List<Event> Is it possible to avoid manual cast?

Alexei
  • 14,350
  • 37
  • 121
  • 240

1 Answers1

0

Use Any like this way

@GET("/event")
suspend fun getEvents(@Query("orgn") base: Int, @Query("event") quote: Int): Response<List<Any>>

then

val eventList: List<Any> = response.body() 
sasikumar
  • 12,540
  • 3
  • 28
  • 48