Skip to content

Commit

Permalink
Merge pull request #5 from lucasmpaim/master
Browse files Browse the repository at this point in the history
Permit a dynamic gson configure
  • Loading branch information
Hazer authored Oct 6, 2017
2 parents 2942460 + 5616eb9 commit 0eb054e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions rest/src/main/java/io/vithor/yamvpframework/rest/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Interceptor>? = null
get() = apiAuthorizations
Expand All @@ -23,15 +26,16 @@ class ApiClient(var baseUrl: String, val interceptor: Interceptor? = null, varar
init {
if (!baseUrl.endsWith("/"))
baseUrl += "/"
apiAuthorizations = LinkedHashMap<String, Interceptor>()
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 {
Expand Down

0 comments on commit 0eb054e

Please sign in to comment.