Sanitizes Retrofit response from null(s) forcing deserializer using Kotlin's default value.
It's pretty simple actually :), it transforms this:
{ "name": "John Doe", "picture": null, "phone_number": null }
to this:
{ "name": "John Doe" }
Because Kotlin needs missing properties in order to create objects with default values. Hence this will be a welcomed addition to you project I reckon :)
Takes a bit of time until it reiterates through all of the entries in your json.
Preferably as OkHttp interceptor:
OkHttpClient.Builder()
.addInterceptor(...)
.addInterceptor(ResponseSanitizer())
.addInterceptor(...)
.build()
or standalone:
val result = Sanitizer { someString.removeNulls() }
In your root build.gradle
allprojects {
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
In your module build.gradle
:
dependencies {
implementation "com.github.diareuse:response-sanitizer:latest.version"
//...or
implementation group: "com.github.diareuse", name: "response-sanitizer", version: "latest.version"
}
OR in your module build.gradle.kts
:
dependencies {
implementation("com.github.diareuse:response-sanitizer:latest.version")
//...or
implementation("com.github.diareuse", "response-sanitizer", "latest.version")
}