Skip to content

Instantly share code, notes, and snippets.

@ziyaddinovchiyev
Created November 12, 2021 10:42
Show Gist options
  • Save ziyaddinovchiyev/c4e495b808ed8ab9f8c9490e69ea7c2e to your computer and use it in GitHub Desktop.
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.
@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