retrofit icon indicating copy to clipboard operation
retrofit copied to clipboard

support return a List that its' element may be null

Open ethi1989 opened this issue 6 months ago • 2 comments

it seems no support the return a List that its' element may be null ,like below example. The function prototype

interface ApiService {
  suspend fun funA(
        @Body ids: List<Long>
    ): Result<BaseResponse<List<ADTO?>>>
}

The Api Provide like below

    fun provideApiService(configure: AppConfigure, okHttpClient: OkHttpClient): ApiService {
        val appJson = Json {
            ignoreUnknownKeys = true
            explicitNulls = true
        }
        return Retrofit.Builder()           
            .client(okHttpClient)
            .baseUrl(configure.baseApiUrl)
            .addConverterFactory(appJson.asConverterFactory("application/json;charset=UTF-8".toMediaType()))
            .addCallAdapterFactory(ResultCallAdapterFactory.create())
            .build().create(ApiService::class.java)
    }

The packet is {"code":0,"data":[{"createTime":"2022-11-23 15:28:29","faceId":123,"faceUrl":"","feature":"ABC"},null,null]}

it is failed, because the null element , how can i to solve this problem? tks

ethi1989 avatar Aug 27 '24 09:08 ethi1989