forked from loafle/openapi-generator-original
Added converterFactories property to ApiClient in jvm-retrofit2. (#15008)
* Added converterFactories property to ApiClient in jvm-retrofit2. * [retrofit2] Supplement deprecate contents of converterFactory * [retrofit2] Supplement deprecate contents of converterFactory * [retrofit2] converterFactory removed. * [retrofit2] sample update. * [retrofit2] Type mismatch fix in Rx.
This commit is contained in:
@@ -7,6 +7,7 @@ import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Converter
|
||||
import retrofit2.CallAdapter
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||
import com.squareup.moshi.Moshi
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
@@ -17,7 +18,12 @@ class ApiClient(
|
||||
private val okHttpClientBuilder: OkHttpClient.Builder? = null,
|
||||
private val serializerBuilder: Moshi.Builder = Serializer.moshiBuilder,
|
||||
private val callFactory : Call.Factory? = null,
|
||||
private val converterFactory: Converter.Factory? = null,
|
||||
private val callAdapterFactories: List<CallAdapter.Factory> = listOf(
|
||||
),
|
||||
private val converterFactories: List<Converter.Factory> = listOf(
|
||||
ScalarsConverterFactory.create(),
|
||||
MoshiConverterFactory.create(serializerBuilder.build()),
|
||||
)
|
||||
) {
|
||||
private val apiAuthorizations = mutableMapOf<String, Interceptor>()
|
||||
var logger: ((String) -> Unit)? = null
|
||||
@@ -25,11 +31,14 @@ class ApiClient(
|
||||
private val retrofitBuilder: Retrofit.Builder by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(MoshiConverterFactory.create(serializerBuilder.build()))
|
||||
.apply {
|
||||
if (converterFactory != null) {
|
||||
addConverterFactory(converterFactory)
|
||||
callAdapterFactories.forEach {
|
||||
addCallAdapterFactory(it)
|
||||
}
|
||||
}
|
||||
.apply {
|
||||
converterFactories.forEach {
|
||||
addConverterFactory(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user