當前位置: 首頁>>代碼示例>>Java>>正文


Java GsonConverter類代碼示例

本文整理匯總了Java中retrofit.converter.GsonConverter的典型用法代碼示例。如果您正苦於以下問題:Java GsonConverter類的具體用法?Java GsonConverter怎麽用?Java GsonConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GsonConverter類屬於retrofit.converter包,在下文中一共展示了GsonConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRestAdapter

import retrofit.converter.GsonConverter; //導入依賴的package包/類
private RestAdapter getRestAdapter(String HOST) {
    File cacheFile = new File(mContext.getApplicationContext().getCacheDir().getAbsolutePath(), "videoCache");
    int cacheSize = 10 * 1024 * 1024;
    Cache cache = new Cache(cacheFile, cacheSize);
    OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
    okBuilder.cache(cache);
    okBuilder.readTimeout(20, TimeUnit.SECONDS);//設置讀取新連接超時
    okBuilder.connectTimeout(10, TimeUnit.SECONDS);//設置新連接的默認連接超時
    okBuilder.writeTimeout(20, TimeUnit.SECONDS);//設置默認為新連接編寫超時
    OkHttpClient client = okBuilder.build();
    //
    RestAdapter.Builder restBuilder = new RestAdapter.Builder();
    restBuilder.setClient(new Ok3Client(client));
    restBuilder.setEndpoint(HOST);//URL_HOST
    restBuilder.setConverter(new GsonConverter(getGson()));//解析
    //
    RestAdapter videoRestAdapter = restBuilder.build();
    videoRestAdapter.setLogLevel(LOG_LEVEL);
    return videoRestAdapter;
}
 
開發者ID:zhao-mingjian,項目名稱:qvod,代碼行數:21,代碼來源:HttpUtils.java

示例2: connectFacebookAccount

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Connects a user's Facebook account - if already registered with another social medium
 *
 * @param userID
 * @param accessToken
 */
public void connectFacebookAccount(@NonNull long userID, @NonNull String accessToken, @NonNull final PDAPICallback<PDUser> callback){
    JsonObject facebookObject = new JsonObject();
    facebookObject.addProperty("id", userID);
    facebookObject.addProperty("access_token", accessToken);

    JsonObject userObject = new JsonObject();
    userObject.add("facebook", facebookObject);

    JsonObject json = new JsonObject();
    json.add("user", userObject);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.connectFacebookAccount(body, callback);
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:27,代碼來源:PDAPIClient.java

示例3: connectWithTwitterAccount

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Connect a users Twitter account
 *
 * @param userID     Twitter User ID
 * @param userToken  Twitter User Token
 * @param userSecret Twitter User Secret
 * @param callback   {@link PDAPICallback} for API result
 */
public void connectWithTwitterAccount(@NonNull String userID, @NonNull String userToken, @NonNull String userSecret, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject twitterObject = new JsonObject();
    twitterObject.addProperty("social_id", userID);
    twitterObject.addProperty("access_token", userToken);
    twitterObject.addProperty("access_secret", userSecret);

    JsonObject userJson = new JsonObject();
    userJson.add("twitter", twitterObject);

    JsonObject json = new JsonObject();
    json.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDTwitterUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.connectWithTwitterAccount(body, callback);
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:30,代碼來源:PDAPIClient.java

示例4: connectWithInstagramAccount

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Connect a users Instagram Account
 *
 * @param userId      Instagram User ID
 * @param accessToken Instagram Access Token
 * @param screenName  Users Screen Name
 * @param callback    {@link PDAPICallback} for API result
 */
public void connectWithInstagramAccount(@NonNull String userId, @NonNull String accessToken, @NonNull String screenName, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject instagramObject = new JsonObject();
    instagramObject.addProperty("id", userId);
    instagramObject.addProperty("access_token", accessToken);
    instagramObject.addProperty("screen_name", screenName);

    JsonObject userJson = new JsonObject();
    userJson.add("instagram", instagramObject);

    JsonObject json = new JsonObject();
    json.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDInstagramUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.connectWithInstagramAccount(body, callback);
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:29,代碼來源:PDAPIClient.java

示例5: disconnectTwitterAccount

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Disconnect users Twitter account
 *
 * @param accessToken  Twitter access token
 * @param accessSecret Twitter access secret
 * @param twitterId    Users Twitter account ID
 * @param callback     {@link PDAPICallback} for API result
 */
public void disconnectTwitterAccount(String accessToken, String accessSecret, String twitterId, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject twitterJson = new JsonObject();
    twitterJson.addProperty("access_token", accessToken);
    twitterJson.addProperty("access_secret", accessSecret);
    twitterJson.addProperty("id", twitterId);

    JsonObject userJson = new JsonObject();
    userJson.add("twitter", twitterJson);

    JsonObject jsonBody = new JsonObject();
    jsonBody.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, jsonBody.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDTwitterUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.disconnectSocialAccount(body, callback);
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:30,代碼來源:PDAPIClient.java

示例6: disconnectInstagramAccount

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Disconnect users Instagram Account
 *
 * @param accessToken Instagram access token
 * @param instagramId Users Instagram account ID
 * @param screenName  Users Instagram screen name
 * @param callback    {@link PDAPICallback} for API result
 */
public void disconnectInstagramAccount(String accessToken, String instagramId, String screenName, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject twitterJson = new JsonObject();
    twitterJson.addProperty("access_token", accessToken);
    twitterJson.addProperty("screen_name", screenName);
    twitterJson.addProperty("id", instagramId);

    JsonObject userJson = new JsonObject();
    userJson.add("instagram", twitterJson);

    JsonObject jsonBody = new JsonObject();
    jsonBody.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, jsonBody.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDInstagramUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.disconnectSocialAccount(body, callback);
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:30,代碼來源:PDAPIClient.java

示例7: disconnectFacebookAccount

import retrofit.converter.GsonConverter; //導入依賴的package包/類
public void disconnectFacebookAccount(@NonNull final String facebookAccessToken,
                                      @NonNull final String facebookUserID,
                                      @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject facebookObject = new JsonObject();
    facebookObject.addProperty("id", facebookUserID);
    facebookObject.addProperty("access_token", facebookAccessToken);

    JsonObject userObject = new JsonObject();
    userObject.add("facebook", facebookObject);

    JsonObject json = new JsonObject();
    json.add("user", userObject);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.disconnectSocialAccount(body, callback);
}
 
開發者ID:Popdeem,項目名稱:Popdeem-SDK-Android,代碼行數:23,代碼來源:PDAPIClient.java

示例8: createApiDescription

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
     * This will always create new instance of api description
     *
     * @return
     */
    public static ApiDescription createApiDescription() {
        disableSSLCertificateVerification();
        return new RestAdapter.Builder()
                .setEndpoint(Storage.getURL())
                .setRequestInterceptor(
                        new RequestInterceptor() {
                            @Override
                            public void intercept(RequestFacade request) {
                                if (!TextUtils.isEmpty(Storage.getCredentials())) {
                                    String string = "Basic " + Storage.getCredentials();
                                    request.addHeader("Authorization", string);
//                            request.addHeader("Content-Type", "");
                                }
                            }
                        })
                .setConverter(new GsonConverter(gson))
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .setClient(getClient()).build()
                .create(ApiDescription.class);
    }
 
開發者ID:easyredmine,項目名稱:mobile_app_android,代碼行數:26,代碼來源:RestServiceGenerator.java

示例9: createRestClient

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Creates a REST client.
 * @param url The URL of the EDD Licensing REST API endpoint.
 * @return A {@link EDDLicensingClient}.
 */
public static EDDLicensingClient createRestClient(String url) {
	
	 Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create();
	 
	RestAdapter restAdapter = new RestAdapter.Builder()
               .setEndpoint(url)
               .setConverter(new GsonConverter(gson))
               .setClient(new OkClient(new OkHttpClient()))
               .build();
	
	EDDLicensingClient client = restAdapter.create(EDDLicensingClient.class);
	
	return client;
	
}
 
開發者ID:jzonthemtn,項目名稱:edd-licensing-java-client,代碼行數:23,代碼來源:EDDLicensingClientFactory.java

示例10: setupRestClient

import retrofit.converter.GsonConverter; //導入依賴的package包/類
public static void setupRestClient(final String token) {
    RequestInterceptor requestInterceptor = new RequestInterceptor() {
        @Override
        public void intercept(RequestFacade request) {
            request.addHeader("Content-Type", "application/json");
            request.addHeader("Authorization", token);
        }
    };

    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

    RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(BASE_URL)
            .setConverter(new GsonConverter(gson))
            .setRequestInterceptor(requestInterceptor)
            .setLogLevel(RestAdapter.LogLevel.FULL);

    RestAdapter restAdapter = builder.build();
    sAppRestApi = restAdapter.create(LetoTogglApi.class);
}
 
開發者ID:letolab,項目名稱:LETO-Toggl_Android,代碼行數:21,代碼來源:LetoTogglRestClient.java

示例11: newApiService

import retrofit.converter.GsonConverter; //導入依賴的package包/類
/**
 * Creates a new preconfigured TraktTvApiService instance.
 */
public static TraktTvApiService newApiService() {

    // Set up rest adapter
    RestAdapter.Builder restAdapterBuilder = new RestAdapter.Builder()
            .setConverter(new GsonConverter(new Gson()))
            .setRequestInterceptor(request -> {
                request.addHeader("Content-type", "application/json");
                request.addHeader("trakt-api-version", "2");
                request.addHeader("trakt-api-key", TraktTvAPIConfiguration.CLIENT_ID);
            })
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setEndpoint(API_ENDPOINT);

    // Build raw api service
    return restAdapterBuilder.build().create(TraktTvApiService.class);
}
 
開發者ID:trivago,項目名稱:Heimdall.droid,代碼行數:20,代碼來源:TraktTvApiFactory.java

示例12: onCreate

import retrofit.converter.GsonConverter; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    sMobilizerApp = this;

    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    mApiInterface = new RestAdapter.Builder().setEndpoint(ApiConstants.BASEAPIURL).setConverter(new GsonConverter(gson)).build().create(ApiInterface.class);
    mApiInterfaceWithoutBase = new RestAdapter.Builder().setEndpoint("http:").setConverter(new GsonConverter(gson)).build().create(ApiInterface.class);

    SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            sUser = null;
        }
    };

    SharedPreferences mSharedPreference = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreference.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
 
開發者ID:Redmart,項目名稱:os-mobilizer-android,代碼行數:20,代碼來源:MobilizerApp.java

示例13: IntercomClient

import retrofit.converter.GsonConverter; //導入依賴的package包/類
public IntercomClient(Intercom intercom) {
  Gson gson = getAPIGsonRegistry();

  OkHttpClient okHttpClient = new OkHttpClient();
  okHttpClient.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
  okHttpClient.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);

  BasicAuthProvider authProvider = new BasicAuthProvider(intercom.getAPP_ID(), intercom.getAPI_KEY());

  intercomApi = new RestAdapter.Builder()
      .setEndpoint(AppConstants.API_HOST)
      .setClient(new OkClient(okHttpClient))
      .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
      .setConverter(new GsonConverter(gson))
      .setRequestInterceptor(authProvider)
      .build();

  userService = intercomApi.create(Users.class);
}
 
開發者ID:creativepsyco,項目名稱:intercom-android-sdk,代碼行數:20,代碼來源:IntercomClient.java

示例14: createBuilder

import retrofit.converter.GsonConverter; //導入依賴的package包/類
protected RestAdapter.Builder createBuilder() {
    Gson gson = new Gson();
    return new RestAdapter.Builder()
            .setClient(client)
            .setConverter(new GsonConverter(gson))
            .setRequestInterceptor(new RequestInterceptor() {
                @Override
                public void intercept(RequestFacade request) {
                    // Tokens are generated for each and every request for now lol!
                    AuthService authService = new AuthServiceImpl(sphereApiConfig.getAuthConfig(),
                            client);
                    Tokens tokens = authService.getAccessTokenObs().toBlocking().first();
                    request.addHeader("Authorization", "Bearer " + tokens.getAccessToken());
                }
            })
            .setEndpoint(buildApiEndpoint());
}
 
開發者ID:z0lope0z,項目名稱:sphere-android-sdk,代碼行數:18,代碼來源:SphereClient.java

示例15: getPhoenixAPIService

import retrofit.converter.GsonConverter; //導入依賴的package包/類
public static PhoenixAPI getPhoenixAPIService() {
    String baseUrl;
    if (BuildConfig.BUILD_TYPE.equals("release")) {
        baseUrl = PhoenixAPI.PRODUCTION_URL;
    }
    else if (BuildConfig.BUILD_TYPE.equals("internal")) {
        baseUrl = PhoenixAPI.THOR_URL;
    }
    else {
        baseUrl = PhoenixAPI.QA_URL;
    }

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(ResponseCampaign.class, new ResponseCampaignDeserializer<ResponseCampaign>())
.registerTypeAdapter(ResponseReportBackList.class, new ResponseReportBackListDeserializer<ResponseReportBackList>())
            .setDateFormat(JSON_DATE_FORMAT_PHOENIX).create();
    GsonConverter gsonConverter = new GsonConverter(gson);
    return getRequestAdapterBuilder().setConverter(gsonConverter)
            .setEndpoint(baseUrl).build().create(PhoenixAPI.class);
}
 
開發者ID:DoSomethingArchive,項目名稱:LetsDoThis-Android,代碼行數:21,代碼來源:NetworkHelper.java


注:本文中的retrofit.converter.GsonConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。