protected S getService ( ) { // No need to recreate it if ( service != null ) { return service ; } Retrofit . Builder retrofitBuilder = new Retrofit . Builder ( ) . baseUrl ( baseUrl ( ) ) . addConverterFactory ( GsonConverterFactory . create ( getGsonBuilder ( ) . create ( ) ) ) ; if ( getCallFactory ( ) != null ) { retrofitBuilder . callFactory ( getCallFactory ( ) ) ; } else { retrofitBuilder . client ( getOkHttpClient ( ) ) ; } retrofit = retrofitBuilder . build ( ) ; service = ( S ) retrofit . create ( serviceType ) ; return service ; }
Creates the Retrofit object and the service if they are not already created . Subclasses can override getGsonBuilder to add anything to the GsonBuilder .