本文整理匯總了Java中retrofit2.converter.gson.GsonConverterFactory.create方法的典型用法代碼示例。如果您正苦於以下問題:Java GsonConverterFactory.create方法的具體用法?Java GsonConverterFactory.create怎麽用?Java GsonConverterFactory.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類retrofit2.converter.gson.GsonConverterFactory
的用法示例。
在下文中一共展示了GsonConverterFactory.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildGsonConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
/**
* 構建GSON轉換器
* @return GsonConverterFactory
*/
private static GsonConverterFactory buildGsonConverterFactory(){
GsonBuilder builder = new GsonBuilder();
builder.setLenient();
// 注冊類型轉換適配器
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return null == json ? null : new Date(json.getAsLong());
}
});
Gson gson = builder.create();
return GsonConverterFactory.create(gson);
}
示例2: setupApiServices
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
private void setupApiServices(String streamingUrl, String recordingUrl) {
OkHttpClient client = new OkHttpClient();
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create();
RxJava2CallAdapterFactory rxJava2CallAdapterFactory = RxJava2CallAdapterFactory.create();
Retrofit retrofitRecordings = new Retrofit.Builder()
.baseUrl(recordingUrl)
.client(client)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJava2CallAdapterFactory)
.build();
mRecordingApiService = retrofitRecordings.create(RecordingService.class);
Retrofit retrofigStreaming = new Retrofit.Builder()
.baseUrl(streamingUrl)
.client(client)
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJava2CallAdapterFactory)
.build();
mStreamingApiService = retrofigStreaming.create(StreamingService.class);
}
示例3: YelpV3APIProvider
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
public YelpV3APIProvider(String client_id, String client_secret) {
httpClient = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.build();
gsonConverterFactory = GsonConverterFactory.create();
yelpAuth = new Retrofit.Builder()
.baseUrl(API_HOST)
.addConverterFactory(gsonConverterFactory)
.client(httpClient)
.build()
.create(YelpOAuth2.class);
this.client_id = client_id;
this.client_secret = client_secret;
}
示例4: createService
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@NonNull
private static <S> S createService(@NonNull Class<S> s, @NonNull String token,
@NonNull String secret) {
final GsonConverterFactory serializer = GsonConverterFactory.create(
new GsonBuilder().registerTypeAdapterFactory(JSONModelTypeAdapterFactory.create())
.create());
final OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(
Config.CONSUMER_KEY, Config.CONSUMER_SECRET);
consumer.setTokenWithSecret(token, secret);
httpClient.addInterceptor(new SigningInterceptor(consumer));
final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(Config.HTTP_LOG_LEVEL);
httpClient.addInterceptor(loggingInterceptor);
final Retrofit client = new Retrofit.Builder().baseUrl(Config.HOST)
.addConverterFactory(serializer)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.client(httpClient.build())
.build();
return client.create(s);
}
示例5: getInstance
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
public static Retrofit getInstance(){
if (retrofit == null) {
OkHttpClient okHttpClient = new OkHttpClient();
OkHttpClient.Builder builder = okHttpClient.newBuilder();
builder.retryOnConnectionFailure(true);
GsonConverterFactory factory = GsonConverterFactory.create();
retrofit = new Retrofit.Builder().client(okHttpClient)
.baseUrl(Constants.BASE_URL)
.addConverterFactory(factory)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
return retrofit;
}
示例6: create
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
public Retrofit create(final Class<?> clazz) {
final retrofit2.Converter.Factory factory = GsonConverterFactory.create(gson);
final OkHttpClient client = httpFactory.create(clazz);
return new Retrofit.Builder()
.baseUrl(this.baseUrl)
.client(client)
.addConverterFactory(factory)
.build();
}
示例7: gsonConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@MyAppComponentScope
@Provides
public GsonConverterFactory gsonConverterFactory(){
return GsonConverterFactory.create();
}
示例8: provideConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
public Converter.Factory provideConverterFactory(Gson gson) {
return GsonConverterFactory.create(gson);
}
示例9: GsonCustomConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
private GsonCustomConverterFactory(Gson gson) {
if (gson == null)
throw new NullPointerException("gson == null");
this.gson = gson;
this.gsonConverterFactory = GsonConverterFactory.create(gson);
}
示例10: provideGsonConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Singleton
@Provides
GsonConverterFactory provideGsonConverterFactory() {
return GsonConverterFactory.create();
}
開發者ID:metao1,項目名稱:Dagger2-Retrofit-MVP-OKHttp3-ButterKnife-Glide-Example,代碼行數:6,代碼來源:ApplicationModule.java
示例11: providesConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
public Converter.Factory providesConverterFactory() {
return GsonConverterFactory.create();
}
示例12: provideGsonConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
Converter.Factory provideGsonConverterFactory() {
return GsonConverterFactory.create();
}
示例13: provideGsonConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
public Converter.Factory provideGsonConverterFactory(Gson gson) {
return GsonConverterFactory.create(gson);
}
示例14: provideConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
public Converter.Factory provideConverterFactory() {
return GsonConverterFactory.create();
}
示例15: provideGsonConverterFactory
import retrofit2.converter.gson.GsonConverterFactory; //導入方法依賴的package包/類
@Provides
@Singleton
Converter.Factory provideGsonConverterFactory() {
return GsonConverterFactory.create();
}