Skip to content

Instantly share code, notes, and snippets.

@rajivrnair
Created September 9, 2020 12:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajivrnair/ddaef641d85b1dc402c72ac7e1cac0b6 to your computer and use it in GitHub Desktop.
Save rajivrnair/ddaef641d85b1dc402c72ac7e1cac0b6 to your computer and use it in GitHub Desktop.
class NullOnEmptyConverterFactory : Converter.Factory() {
override fun responseBodyConverter(type: Type, annotations: Array<Annotation>, retrofit: Retrofit): Converter<ResponseBody, *> {
val delegate: Converter<ResponseBody, Any> = retrofit.nextResponseBodyConverter(this, type, annotations)
return Converter { body -> if (body.contentLength() == 0L) null else delegate.convert(body) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment