diff --git a/app/src/main/java/com/huanchengfly/tieba/api/retrofit/NullOnEmptyConverterFactory.java b/app/src/main/java/com/huanchengfly/tieba/api/retrofit/NullOnEmptyConverterFactory.java deleted file mode 100644 index f54b2f37..00000000 --- a/app/src/main/java/com/huanchengfly/tieba/api/retrofit/NullOnEmptyConverterFactory.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.huanchengfly.tieba.api.retrofit; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import okhttp3.ResponseBody; -import retrofit2.Converter; -import retrofit2.Retrofit; - -public class NullOnEmptyConverterFactory extends Converter.Factory { - @Override - public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { - final Converter delegate = retrofit.nextResponseBodyConverter(this, type, annotations); - return (Converter) body -> { - if (body.contentLength() == 0) return null; - return delegate.convert(body); - }; - } -} diff --git a/app/src/main/java/com/huanchengfly/tieba/api/retrofit/NullOnEmptyConverterFactory.kt b/app/src/main/java/com/huanchengfly/tieba/api/retrofit/NullOnEmptyConverterFactory.kt new file mode 100644 index 00000000..8a3771dd --- /dev/null +++ b/app/src/main/java/com/huanchengfly/tieba/api/retrofit/NullOnEmptyConverterFactory.kt @@ -0,0 +1,16 @@ +package com.huanchengfly.tieba.api.retrofit + +import okhttp3.ResponseBody +import retrofit2.Converter +import retrofit2.Retrofit +import java.lang.reflect.Type + +class NullOnEmptyConverterFactory : Converter.Factory() { + override fun responseBodyConverter(type: Type, annotations: Array, retrofit: Retrofit): Converter? { + val delegate: Converter = retrofit.nextResponseBodyConverter(this, type, annotations) + return (Converter { body: ResponseBody -> + if (body.contentLength() == 0L) return@Converter null + delegate.convert(body) + }) + } +} \ No newline at end of file