当前位置: 首页>>代码示例>>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;未经允许,请勿转载。