com.aliyun.datahub.client.http.protocol.converter.EmptyConverterFactory Maven / Gradle / Ivy
The newest version!
package com.aliyun.datahub.client.http.protocol.converter;
import com.aliyun.datahub.client.model.BaseResult;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.Nullable;
import retrofit2.Converter;
import java.io.IOException;
public abstract class EmptyConverterFactory {
public static Converter, RequestBody> requestConverter() {
return null;
}
public static Converter responseConverter(Class extends BaseResult> cls) {
return new EmptyResponseConverter<>(cls);
}
private static class EmptyResponseConverter implements Converter {
private final Class cls;
public EmptyResponseConverter(Class cls) {
this.cls = cls;
}
@Nullable
@Override
public T convert(ResponseBody body) throws IOException {
body.close();
try {
return cls.newInstance();
} catch (Exception e) {
return null;
}
}
}
}