diff --git a/rest/src/main/java/io/vithor/yamvpframework/rest/api/ApiClient.kt b/rest/src/main/java/io/vithor/yamvpframework/rest/api/ApiClient.kt index f29d900..1a8b47e 100644 --- a/rest/src/main/java/io/vithor/yamvpframework/rest/api/ApiClient.kt +++ b/rest/src/main/java/io/vithor/yamvpframework/rest/api/ApiClient.kt @@ -10,7 +10,10 @@ import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import java.util.* -class ApiClient(var baseUrl: String, val interceptor: Interceptor? = null, vararg var providedInterceptors: Interceptor?) { +class ApiClient(var baseUrl: String, + val interceptor: Interceptor? = null, + vararg var providedInterceptors: Interceptor?, + gsonConfigure: ((builder: GsonBuilder) -> Unit)? = null) { var apiAuthorizations: MutableMap? = null get() = apiAuthorizations @@ -23,15 +26,16 @@ class ApiClient(var baseUrl: String, val interceptor: Interceptor? = null, varar init { if (!baseUrl.endsWith("/")) baseUrl += "/" - apiAuthorizations = LinkedHashMap() - createDefaultAdapter(baseUrl) + apiAuthorizations = LinkedHashMap() + createDefaultAdapter(baseUrl, gsonConfigure) } - fun createDefaultAdapter(baseUrl: String) { - val gson = GsonBuilder() + fun createDefaultAdapter(baseUrl: String, gsonConfigure: ((builder: GsonBuilder) -> Unit)?) { + val gsonBuilder = GsonBuilder() // .registerTypeAdapter(Date.class, new GsonDateMultiDeserializer()) .setDateFormat("EEE, dd MMM yyyy HH:mm:ss z") - .create() + gsonConfigure?.invoke(gsonBuilder) + val gson = gsonBuilder.create() val okBuilder = OkHttpClient.Builder() .addInterceptor {