All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 requestConverter() {
        return null;
    }

    public static Converter responseConverter(Class 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;
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy