本文整理汇总了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();
}