Skip to content

Instantly share code, notes, and snippets.

@andersonkxiass
Last active September 18, 2017 13:07
Show Gist options
  • Save andersonkxiass/12cdf08dbf72a848b06f1e90b1ecea35 to your computer and use it in GitHub Desktop.
Save andersonkxiass/12cdf08dbf72a848b06f1e90b1ecea35 to your computer and use it in GitHub Desktop.
public interface Api {
String API_BASE_URL = "http://your.domain.here";
class Factory {
public static <S> S create(Class<S> service) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
//JacksonConverterFactory adding TaskDeserializer to SimpleModule
SimpleModule module = new SimpleModule();
module.addDeserializer(TaskDeserializer.class, new TaskDeserializer());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(module);
Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(JacksonConverterFactory.create(objectMapper));
Retrofit retrofit = builder.client(httpClient.build())
.build();
return retrofit.create(service);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment