Created
November 12, 2021 10:42
-
-
Save ziyaddinovchiyev/c4e495b808ed8ab9f8c9490e69ea7c2e to your computer and use it in GitHub Desktop.
Excludes the empty string properties from request body. Simply add dd this gson object to your retrofit client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Provides | |
fun provideGson() : Gson = GsonBuilder().registerTypeAdapter(String::class.java ,object : TypeAdapter<String>() { | |
override fun write(out: JsonWriter?, value: String?) { | |
if(value.isNullOrBlank()) { | |
out?.nullValue() | |
return | |
} | |
out?.value(value) | |
} | |
override fun read(inn: JsonReader?): String? { | |
return inn?.nextString() | |
} | |
}).create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment