retrofit2.Retrofit.converterFactories()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中retrofit2.Retrofit.converterFactories方法的一些代码示例,展示了Retrofit.converterFactories的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Retrofit.converterFactories方法的具体详情如下:
包路径:retrofit2.Retrofit
类名称:Retrofit
方法名:converterFactories

Retrofit.converterFactories介绍

[英]Returns an unmodifiable list of the factories tried when creating a #requestBodyConverter(Type,Annotation[],Annotation[]), a #responseBodyConverter(Type,Annotation[]), or a #stringConverter(Type,Annotation[]).
[中]返回创建#requestBodyConverter(类型,注释[],注释[])、#responseBodyConverter(类型,注释[])或#stringConverter(类型,注释[])时尝试的工厂的不可修改列表。

代码示例

代码示例来源:origin: WallaceXiao/StockChart-MPAndroidChart

List<Converter.Factory> listConverterFactory = EasyHttp.getRetrofit().converterFactories();
for (Converter.Factory factory : listConverterFactory) {
  retrofitBuilder.addConverterFactory(factory);

代码示例来源:origin: kongpengcheng/SmartRetrofit

@SuppressWarnings("unchecked")
  public static <T> T bytesToResponse(Retrofit retrofit, Type dataType, Annotation[] annotations,
                    byte[] data){
    for(Converter.Factory factory : retrofit.converterFactories()){
      if(factory == null) continue;
      Converter<ResponseBody, T> converter =
          (Converter<ResponseBody, T>) factory.responseBodyConverter(dataType, annotations, retrofit);

      if(converter != null){
        try {
          return converter.convert(ResponseBody.create(null, data));
        }catch(IOException | NullPointerException exc){
          Log.e("SmartCall", "", exc);
        }
      }
    }

    return null;
  }
}

代码示例来源:origin: lizubing1992/Smartcacheforretrofit2

@SuppressWarnings("unchecked")
  public static <T> T bytesToResponse(Retrofit retrofit, Type dataType, Annotation[] annotations,
                    byte[] data){
    for(Converter.Factory factory : retrofit.converterFactories()){
      if(factory == null) continue;
      Converter<ResponseBody, T> converter =
          (Converter<ResponseBody, T>) factory.responseBodyConverter(dataType, annotations, retrofit);

      if(converter != null){
        try {
          return converter.convert(ResponseBody.create(null, data));
        }catch(IOException | NullPointerException exc){
          Log.e("SmartCall", "", exc);
        }
      }
    }

    return null;
  }
}

代码示例来源:origin: dimitrovskif/SmartCache

@SuppressWarnings("unchecked")
  public static <T> T bytesToResponse(Retrofit retrofit, Type dataType, Annotation[] annotations,
                    byte[] data){
    for(Converter.Factory factory : retrofit.converterFactories()){
      if(factory == null) continue;
      Converter<ResponseBody, T> converter =
          (Converter<ResponseBody, T>) factory.responseBodyConverter(dataType, annotations,
              retrofit);

      if(converter != null){
        try {
          return converter.convert(ResponseBody.create(null, data));
        }catch(IOException | NullPointerException exc){
          Log.e("SmartCall", "", exc);
        }
      }
    }

    return null;
  }
}

代码示例来源:origin: iagocanalejas/retrocache

@SuppressWarnings("unchecked")
public static <T> T bytesToResponse(Retrofit retrofit, Type dataType, Annotation[] annotations, byte[] data) {
  for (Converter.Factory factory : retrofit.converterFactories()) {
    if (factory == null) {
      continue;
    }
    Converter<ResponseBody, T> converter =
        (Converter<ResponseBody, T>) factory.responseBodyConverter(
            dataType, annotations, retrofit);
    if (converter != null) {
      try {
        return converter.convert(ResponseBody.create(null, data));
      } catch (IOException | NullPointerException exc) {
        Log.e("CachedCall", "", exc);
      }
    }
  }
  return null;
}

代码示例来源:origin: lygttpod/RxHttpUtils

List<Converter.Factory> listConverterFactory = RetrofitClient.getInstance().getRetrofit().converterFactories();
for (Converter.Factory factory : listConverterFactory) {
  singleRetrofitBuilder.addConverterFactory(factory);

代码示例来源:origin: lizubing1992/Smartcacheforretrofit2

@SuppressWarnings("unchecked")
public static <T> byte[] responseToBytes(Retrofit retrofit, T data, Type dataType,
                   Annotation[] annotations){
  for(Converter.Factory factory : retrofit.converterFactories()){
    if(factory == null) continue;
    Converter<T, RequestBody> converter =
        (Converter<T, RequestBody>) factory.requestBodyConverter(dataType, annotations,null,retrofit);
    if(converter != null){
      Buffer buff = new Buffer();
      try {
        converter.convert(data).writeTo(buff);
      }catch(IOException ioException){
        continue;
      }
      return buff.readByteArray();
    }
  }
  return null;
}

代码示例来源:origin: dimitrovskif/SmartCache

@SuppressWarnings("unchecked")
public static <T> byte[] responseToBytes(Retrofit retrofit, T data, Type dataType,
                   Annotation[] annotations){
  for(Converter.Factory factory : retrofit.converterFactories()){
    if(factory == null) continue;
    Converter<T, RequestBody> converter =
        (Converter<T, RequestBody>) factory.requestBodyConverter(dataType, annotations,
            null, retrofit);
    if(converter != null){
      Buffer buff = new Buffer();
      try {
        converter.convert(data).writeTo(buff);
      }catch(IOException ioException){
        continue;
      }
      return buff.readByteArray();
    }
  }
  return null;
}

代码示例来源:origin: kongpengcheng/SmartRetrofit

@SuppressWarnings("unchecked")
public static <T> byte[] responseToBytes(Retrofit retrofit, T data, Type dataType,
                   Annotation[] annotations){
  for(Converter.Factory factory : retrofit.converterFactories()){
    if(factory == null) continue;
    Converter<T, RequestBody> converter =
        (Converter<T, RequestBody>) factory.requestBodyConverter(dataType, annotations,null,retrofit);
    if(converter != null){
      Buffer buff = new Buffer();
      try {
        converter.convert(data).writeTo(buff);
      }catch(IOException ioException){
        continue;
      }
      return buff.readByteArray();
    }
  }
  return null;
}

代码示例来源:origin: iagocanalejas/retrocache

@SuppressWarnings("unchecked")
public static <T> byte[] responseToBytes(Retrofit retrofit, T data, Type dataType, Annotation[] annotations) {
  if (data == null) {
    return null;
  }
  for (Converter.Factory factory : retrofit.converterFactories()) {
    if (factory == null) {
      continue;
    }
    Converter<T, RequestBody> converter;
    converter = (Converter<T, RequestBody>) factory.requestBodyConverter(
        dataType, annotations, null, retrofit);
    if (converter != null) {
      Buffer buff = new Buffer();
      try {
        converter.convert(data).writeTo(buff);
      } catch (IOException ioException) {
        continue;
      }
      return buff.readByteArray();
    }
  }
  return null;
}

相关文章