Adapter for retrofit calls
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Fixed bug causing undefined behavior with kotlin preprocessors Feb 20, 2019
LICENCE added readme Jul 1, 2018 added ignore Aug 16, 2018
build.gradle added ignore Aug 16, 2018
gradlew initial commit Jul 1, 2018
gradlew.bat initial commit Jul 1, 2018

Retrofit 2 generic response adapter

GitHub license Download


Retrofit 2 call adapter used to wrap your call adapter.
As soon as request finishes(or not) you can get access to response and add some logic just before transferring it further.



Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {

Step 2. Add the dependency

compile 'codes.titanium:preprocessor:1.1.2'

Basic Usage

Main features:

  • Process every entity(or even range of entities) you want before main consumer
  • Add generic error handler
  • Ignore requests you don't want to preprocess
  • Versatile and simple API
  • Works with any call adapter(RxJava1, Rxjava2 etc)
  • Easy setup

Create some Preprocessors

Preprocessor<Observable<TestEntity>> preprocessor = new Preprocessor<Observable<TestEntity>>() {
      public Observable<TestEntity> preprocess(Observable<TestEntity> source) {
        //preprocess observable here
        return source.doOnNext(testEntity -> {
          //save to database
          //some business logic

Add all of them into list:

List<Preprocessor> preprocessors = new ArrayList();

Init retrofit client:

 Retrofit retrofit = new Retrofit.Builder()
        .addCallAdapterFactory(PreprocessAdapter.create(/*Any your call adapter*/, preprocessors))

What happens next?
All entities with this type will be processed before main consumer.

Preprocess ignore

Add annotation to api call that you don't want to preprocess and thats all.

public interface YourAwesomeApiService {
  Observable<List<Cookies>> getCookies();

  //All preprocessors related to Cookies will be ignored here
  Observable<Cookie> editCookie(@Body EditCookiesProtocol protocol);

Wildcard preprocessors

You can use wildcards and multiple preprocessors with same signature to preprocess wide spectrum of types
Preprocessor for every request that makes one retry in case of error:

Preprocessor<Observable<?>> retryPreprocessor = new Preprocessor<Observable<?>>() {
      public Observable<?> preprocess(Observable<?> source) {
        return source.retry(1);

Preprocessor that saves all cookies and its subclass inside cache:

Cache cache = dependenciesProvider.getCache();
Preprocessor<Observable< extends Cookie>> cookiePreprocessor = new Preprocessor<Observable<? extends Cookie>>() {
      public Observable<? extends Cookie> preprocess(Observable<? extends Cookie> source) {
        return source.doOnNext(cookie -> cache.SaveCookie(cookie));


If you are using proguard add this into your

# Premapper
-keepclasseswithmembernames class * implements codes.titanium.premapper.Preprocessor {
    public ** preprocess(**);


  • Preprocessor priority

Release notes


  • Initial release


  • Removed unnecessary abstract method from Preprocessor
  • Can wrap any call adapter
  • Added optional ignore for premap
  • Added support of multiple preprocessors
  • Added support of wildcard preprocessors


  • Preprocessor lazy initialization


  • Fixed bug causing undefined behavior with kotlin preprocessors