当前位置: 首页>>代码示例>>Java>>正文


Java GsonConverterFactory类代码示例

本文整理汇总了Java中retrofit2.converter.gson.GsonConverterFactory的典型用法代码示例。如果您正苦于以下问题:Java GsonConverterFactory类的具体用法?Java GsonConverterFactory怎么用?Java GsonConverterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GsonConverterFactory类属于retrofit2.converter.gson包,在下文中一共展示了GsonConverterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrofit

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
public static Retrofit retrofit() {
    if (mRetrofit == null) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        if (BuildConfig.DEBUG) {
            // Log信息拦截器
            HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            //设置 Debug Log 模式
            builder.addInterceptor(loggingInterceptor);
        }
        OkHttpClient okHttpClient = builder.build();
        mRetrofit = new Retrofit.Builder()
                .baseUrl(ApiStores2.URL_BASE)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
    }
    return mRetrofit;
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:22,代码来源:AppClient2.java

示例2: NetWorkManager

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
private NetWorkManager() {
    this.mOkHttpClient = RetrofitUrlManager.getInstance().with(new OkHttpClient.Builder()) //RetrofitUrlManager 初始化
            .readTimeout(5, TimeUnit.SECONDS)
            .connectTimeout(5, TimeUnit.SECONDS)
            .build();

    this.mRetrofit = new Retrofit.Builder()
            .baseUrl(APP_DEFAULT_DOMAIN)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//使用rxjava
            .addConverterFactory(GsonConverterFactory.create())//使用Gson
            .client(mOkHttpClient)
            .build();

    this.mOneApiService = mRetrofit.create(OneApiService.class);
    this.mTwoApiService = mRetrofit.create(TwoApiService.class);
    this.mThreeApiService = mRetrofit.create(ThreeApiService.class);
}
 
开发者ID:JessYanCoding,项目名称:RetrofitUrlManager,代码行数:18,代码来源:NetWorkManager.java

示例3: apiManager

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
public static ChatDemoApi apiManager(){

        if(chatDemoApi == null){

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();

            logging.setLevel(HttpLoggingInterceptor.Level.BODY);

            OkHttpClient okHttpClient = new OkHttpClient.Builder()
                    .addInterceptor(logging)
                    .connectTimeout(10, TimeUnit.SECONDS)
                    .readTimeout(10, TimeUnit.SECONDS)
                    .build();

            Retrofit client = new Retrofit.Builder()
                    .baseUrl(EndPointConstant.BASE_URL)
                    .client(okHttpClient)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();


            chatDemoApi = client.create(ChatDemoApi.class);
        }

        return chatDemoApi;
    }
 
开发者ID:orbismobile,项目名称:android-chat-namespace-socketio,代码行数:27,代码来源:ChatDemoApiManager.java

示例4: getRetrofit

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
public static RetrofitInterface getRetrofit(String token) {

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

        httpClient.addInterceptor(chain -> {

            Request original = chain.request();
            Request.Builder builder = original.newBuilder()
                    .addHeader("x-access-token", token)
                    .method(original.method(),original.body());
            return  chain.proceed(builder.build());

        });

        RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());

        return new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .client(httpClient.build())
                .addCallAdapterFactory(rxAdapter)
                .addConverterFactory(GsonConverterFactory.create())
                .build().create(RetrofitInterface.class);
    }
 
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:24,代码来源:NetworkUtil.java

示例5: Api

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
private Api() {
    HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
    logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
    Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .readTimeout(7676, TimeUnit.MILLISECONDS)
            .connectTimeout(7676, TimeUnit.MILLISECONDS)
            .addInterceptor(headInterceptor)
            .addInterceptor(logInterceptor)
            .addNetworkInterceptor(new HttpCacheInterceptor())
            .cache(cache)
            .build();

    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();

    retrofit = new Retrofit.Builder()
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .baseUrl(C.BASE_URL)
            .build();
    service = retrofit.create(ApiService.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Api.java

示例6: creatService

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
/**
 * 创建ApiService实例
 *
 * @param service Service类型
 * @param <T>
 * @return
 */
private static <T> T creatService(final Class<T> service) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(AppData.LOG_DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);

    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(CONNECT_TIME_OUT_SECONDS, TimeUnit.SECONDS)
            .readTimeout(READ_TIME_OUT_SECONDS, TimeUnit.SECONDS)
            .addInterceptor(new LoggingInterceptor())
            .addInterceptor(new ParamsInterceptord())
            .build();

    return new Retrofit.Builder()
            .baseUrl(AppData.BaseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(client)
            .build()
            .create(service);
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:27,代码来源:ApiManager.java

示例7: RemoteHelper

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
private RemoteHelper(){
    mOkHttpClient = new OkHttpClient.Builder()
            .addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = chain.request();

                            //在这里获取到request后就可以做任何事情了
                            Response response = chain.proceed(request);
                            Log.d(TAG, "intercept: "+request.url().toString());
                            return response;
                        }
                    }
            ).build();

    mRetrofit = new Retrofit.Builder()
            .client(mOkHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl(Constant.API_BASE_URL)
            .build();
}
 
开发者ID:newbiechen1024,项目名称:NovelReader,代码行数:24,代码来源:RemoteHelper.java

示例8: onCustomApiCall

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
public void onCustomApiCall(View view) {
    final String name = "18688994275";
    final String pass = "123456";
    final CustomRequest request = EasyHttp.custom()
            .addConverterFactory(GsonConverterFactory.create(new Gson()))
            .sign(true)
            .timeStamp(true)
            .params(ComParamContact.Login.ACCOUNT, name)
            .params(ComParamContact.Login.PASSWORD, MD5.encrypt4login(pass, AppConstant.APP_SECRET))
            .build();

    LoginService mLoginService = request.create(LoginService.class);
    Observable<AuthModel> observable = request.apiCall(mLoginService.login("v1/account/login", request.getParams().urlParamsMap));
    Disposable disposable = observable.subscribe(new Consumer<AuthModel>() {
        @Override
        public void accept(@NonNull AuthModel authModel) throws Exception {
            showToast(authModel.toString());
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(@NonNull Throwable throwable) throws Exception {
            showToast(throwable.getMessage());
        }
    });
    //EasyHttp.cancelSubscription(disposable);//取消订阅
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:27,代码来源:MainActivity.java

示例9: getProtocore

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
default ProtoCore getProtocore() {
    Gson gson = NetworkUtilities.getGson();
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(getSatispayContext().getBaseUrl())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(
                    getProtocoreHttpClientProvider().getProtocoreClient(
                            getSatispayContext(),
                            getSecurePersistenceManager(),
                            getSessionManager(),
                            getSdkDeviceInfo()
                    )
            )
            .build();
    return retrofit.create(ProtoCore.class);
}
 
开发者ID:satispay,项目名称:in-store-api-java-sdk,代码行数:18,代码来源:ProtoCoreProvider.java

示例10: create

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
private static Retrofit create() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    builder.readTimeout(10, TimeUnit.SECONDS);
    builder.connectTimeout(9, TimeUnit.SECONDS);
    builder.addNetworkInterceptor(new StethoInterceptor());

    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(interceptor);
    }

    return new Retrofit.Builder().baseUrl(ENDPOINT)
            .client(builder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RetrofitProvider.java

示例11: retrofit

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
@Provides Retrofit retrofit() {
  OkHttpClient client = new OkHttpClient.Builder()
      .addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
          return chain.proceed(
              chain.request()
                  .newBuilder()
                  .addHeader("Authorization", "Client-ID " + ImgurService.CLIENT_ID)
                  .build());
        }
      })
      .build();
  return new Retrofit.Builder()
      .client(client)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .baseUrl("https://api.imgur.com/3/")
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:ApiModule.java

示例12: main

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
public static void main(String... args) throws IOException, InterruptedException {
  MockWebServer server = new MockWebServer();
  server.start();
  server.enqueue(new MockResponse());

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(server.url("/"))
      .addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create()))
      .build();
  Service service = retrofit.create(Service.class);

  Call<ResponseBody> call = service.example(new Filter("123"));
  Response<ResponseBody> response = call.execute();
  // TODO handle user response...

  // Print the request path that the server saw to show the JSON query param:
  RecordedRequest recordedRequest = server.takeRequest();
  System.out.println(recordedRequest.getPath());

  server.shutdown();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:JsonQueryParameters.java

示例13: ApiClient

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
private ApiClient() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .addInterceptor(new SessionInterceptor())
            //.addInterceptor(new GzipRequsetInterceptor())
            .build();
    OKHttpUtils.cancelCallWithTag(client);
    this.retrofit = new Retrofit.Builder()
            .baseUrl(API_HOST)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
}
 
开发者ID:luffyke,项目名称:beegoapix-android-demo,代码行数:17,代码来源:ApiClient.java

示例14: beforeEachTest

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
@Before public void beforeEachTest() {

        server = new MockWebServer();

        NumbersWebService numberAPI =
                new Retrofit.Builder()
                        .baseUrl(server.url("/").toString())
                        .addConverterFactory(GsonConverterFactory.create())
                        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                        .build()
                        .create(NumbersWebService.class);

        infrastructure = new TriviaInfrastructure(
                numberAPI,
                new TriviaGenerator(),
                new PayloadMapper(),
                new PayloadValidator(),
                Schedulers.trampoline() // non-concurrent integration on tests
        );
    }
 
开发者ID:ubiratansoares,项目名称:reactive-architectures-playground,代码行数:21,代码来源:TriviaInfrastructureTests.java

示例15: setUp

import retrofit2.converter.gson.GsonConverterFactory; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
    mMockServer = new MockWebServer();
    mMockServer.start();
    Retrofit retrofit = (new Retrofit.Builder().baseUrl(mMockServer.url("").toString())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())).build();
    CivifyLoginService civifyLoginService = retrofit.create(CivifyLoginService.class);
    CivifyMeService civifyMeService = retrofit.create(CivifyMeService.class);
    SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
    mSharedPreferences = mock(SharedPreferences.class);
    mLoginFinishedCallbackMock = mock(LoginFinishedCallback.class);
    when(mSharedPreferences.edit()).thenReturn(editor);
    mUser = new User("username", "name", "surname",
            "email", "password", "password");
    mLoginAdapter =
            new LoginAdapterImpl(civifyLoginService, civifyMeService, mSharedPreferences);
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:19,代码来源:LoginAdapterImplTest.java


注:本文中的retrofit2.converter.gson.GsonConverterFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。