I am in the process of writing code to access my Webservice from my android client. At the minute I am using retrofit to return an observable type for the various calls.At the moment I have 4 of these (shown below)
@FormUrlEncoded
@POST("/app/{pathto}")
Observable<List<EntryItem>> getNewsAndComments(@Path("pathto") String pathto, @FieldMap Map<String, String> fieldnames);
/**
* adding a comment. returns observable
* with message entity type
*
* @param pathto
* @param fieldnames
* @return
*/
@FormUrlEncoded
@POST("/app/{pathto}")
Observable<message> postComment(@Path("pathto") String pathto, @FieldMap Map<String, String> fieldnames);
@FormUrlEncoded
@POST("/{pathto}")
Call<message> regDevice(@Path("pathto") String pathto ,@FieldMap Map<String, String> fieldnames);
/**
* return a Map of canteen menu items!
*
* @param path
* @param fielditems
* @return
*/
@FormUrlEncoded
@POST("/app/{pathto}")
Observable<Map<String, ArrayList<CantItem>>> getCanteenItems(@Path("path") String path, @FieldMap Map<String,String> fielditems);
I also use a generic RestService factory to create the generic retrofit service. I stole this from a blog post I was reading :) .
public static <T> T getRetroFitService(final Class<T> clazz, final String endpoint)
{
final Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(endpoint)
.build();
T service = retrofit.create(clazz);
return service;
}
In my Interface where I Return of an observable etc a lot of the method calls look the same so I tried changing this to the following generic call
Observable<List<T>>
Unfortunately, retrofit doesn't seem to like this. I was wondering is there any way around this so I can make the interface calls even more generic for example passing in my own TypeAdapter to the RestServiceFactory? Also, I am relatively new to retrofit and rx-android so any advice is appreciated. Thanks!