
Retrofit2 를 이용해 API 통신을 하던 도중 오류가 떴다.

java.io.EOFException: End of input at line 1 column 1 path $
찾아보니 Response body 값이 null 일 때 발생하는 오류였다.
class NullOnEmptyConverterFactory : Converter.Factory() {
    fun converterFactory() = this
    override fun responseBodyConverter(type: Type, annotations: Array<out Annotation>, retrofit: Retrofit) = object : Converter<ResponseBody, Any?> {
        val nextResponseBodyConverter = retrofit.nextResponseBodyConverter<Any?>(converterFactory(), type, annotations)
        override fun convert(value: ResponseBody) = if (value.contentLength() != 0L) {
            try{
                nextResponseBodyConverter.convert(value)
            }catch (e:Exception){
                e.printStackTrace()
                null
            }
        } else{
            null
        }
    }
}
val retrofit: Retrofit
	get() = Retrofit.Builder()
		.baseUrl(URL)
		.addConverterFactory(NullOnEmptyConverterFactory())
		.addConverterFactory(GsonConverterFactory.create())
		.build()
NullOnEmptyConverterFactory 설정을 GsonConverterFactory 보다 더 위에 설정해줘야한다.
아래에 하면 Exception 이 그대로 발생함 !