當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。