content: package com.lib.http;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  import retrofit2.Converter;
  
  /**
   * Copyright (C) 2016,深圳市红鸟网络科技股份有限公司 All rights reserved.
   * 项目名称：
   * 类的描述：
   * 创建人员：Robi
   * 创建时间：2016/10/24 11:31
   * 修改人员：Robi
   * 修改时间：2016/10/24 11:31
   * 修改备注：
   * Version: 1.0.0
   */
  public class Factory {
      public static Converter.Factory getFactory() {
          Converter.Factory gsonFactory = checkFactory("retrofit2.converter.gson.GsonConverterFactory");
          Converter.Factory jacksonFactory = checkFactory("retrofit2.converter.jackson.JacksonConverterFactory");
  
          //优先使用jackson
          if (jacksonFactory != null) {
              return jacksonFactory;
          }
          return gsonFactory;
      }
  
      public static Converter.Factory checkFactory(String className) {
          Converter.Factory factory = null;
          try {
              final Class<?> factoryName = Class.forName(className);
              final Method create = factoryName.getMethod("create");
              factory = (Converter.Factory) create.invoke(null);
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          } catch (NoSuchMethodException e) {
              e.printStackTrace();
          } catch (InvocationTargetException e) {
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              e.printStackTrace();
          }
          return factory;
      }
  }
  