com.lzy.okgo.convert.Converter Java Examples

The following examples show how to use com.lzy.okgo.convert.Converter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Request.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
     * @return Converter 允许为null,调用处注意处理
     */
    @Nullable
    public Converter<T> getConverter() {
        // converter 优先级高于 callback
        if (converter == null) converter = callback;
        //removed by fee 2020-04-07: 允许为 null,调用层注意处理
//        HttpUtils.checkNotNull(converter, "converter == null, do you forget to call Request#converter(Converter<T>) ?");
        return converter;
    }
 
Example #2
Source File: BaseCachePolicy.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/** 同步的方式请求网络 **/
    protected Response<T> requestNetworkSync() {
        try {
            okhttp3.Response response = rawCall.execute();
            int responseCode = response.code();

            //network error
            if (responseCode == 404 || responseCode >= 500) {
                return Response.error(false, rawCall, response, HttpException.NET_ERROR());
            }
            Converter<T> respConverter = request.getConverter();
            T body = null;
            if (respConverter != null) {
                body = respConverter.convertResponse(response);
            }
            else {
                OkLogger.e(TAG, "-->requestNetworkSync() respConverter is null...");
            }
//            T body = request.getConverter().convertResponse(response);
            //save cache when request is successful
            saveCache(response.headers(), body);
            return Response.success(false, body, rawCall, response);
        } catch (Throwable throwable) {
            if (throwable instanceof SocketTimeoutException && currentRetryCount < request.getRetryCount()) {
                currentRetryCount++;
                rawCall = request.getRawCall();
                if (canceled) {
                    rawCall.cancel();
                } else {
                    requestNetworkSync();
                }
            }
            return Response.error(false, rawCall, null, throwable);
        }
    }
 
Example #3
Source File: Request.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public Converter<T> getConverter() {
    // converter 优先级高于 callback
    if (converter == null) converter = callback;
    HttpUtils.checkNotNull(converter, "converter == null, do you forget to call Request#converter(Converter<T>) ?");
    return converter;
}