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

top.jfunc.common.http.converter.bean.BeanOkHttp3SmartHttpClient Maven / Gradle / Ivy

Go to download

http客户端请求工具类,有多种实现:OKHttp3、ApacheHttpClient、HttpURLConnection,可以随意切换http实现

There is a newer version: 1.8.2.0
Show newest version
package top.jfunc.common.http.converter.bean;

import top.jfunc.common.converter.Converter;
import top.jfunc.common.http.smart.OkHttp3SmartHttpClient;
import top.jfunc.common.http.smart.Request;

import java.io.IOException;
import java.util.Objects;

import static top.jfunc.common.converter.Converter.checkNull;


/**
 * 返回结果String转换为 Bean
 * @author xiongshiyan at 2018/1/11
 */
public class BeanOkHttp3SmartHttpClient extends OkHttp3SmartHttpClient implements BeanSmartHttpClient {

    private Converter converter;
    public BeanOkHttp3SmartHttpClient(Converter converter){
        this.converter = Objects.requireNonNull(converter);
    }
    public BeanOkHttp3SmartHttpClient(){}

    @Override
    public BeanSmartHttpClient setConverter(Converter converter) {
        this.converter = Objects.requireNonNull(converter);
        return this;
    }

    @Override
    public  T get(Request request , Class clazz) throws IOException {
        checkNull(this.converter);
        String result = get(request).getBody();
        return this.converter.convert(result , clazz);
    }

    @Override
    public  T post(Request request, Class clazz) throws IOException {
        checkNull(this.converter);
        String result = post(request).getBody();
        return this.converter.convert(result , clazz);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy