![]() The guide shows how to use Gson to ingest data from the Rotten Tomatoes API, but it can be used in the same way for any RESTful web service. See this guide about leveraging the Gson library for more information about how to create your own Java classes for use with Retrofit. Manual approach - Creating Java classes by hand We encourage you to follow the manual way to best understand how the auto-generated code approach works. The second approach is you can also auto-generate the Java classes you need by capturing the JSON output and using jsonschema2pojo. The first way is the manual approach, which requires you to learn how to use the Gson library. There are two approaches discussed in this guide. ConverterĬom.squareup.retrofit2:converter-gson:2.9.0Ĭom.squareup.retrofit2:converter-jackson:2.9.0Ĭom.squareup.retrofit2:converter-moshi:2.9.0Ĭom.squareup.retrofit2:converter-protobuf:2.9.0Ĭom.squareup.retrofit2:converter-wire:2.9.0Ĭom.squareup.retrofit2:converter-simplexml:2.9.0 However, there are a few limitations, so if you are not sure which one to choose, use the Gson converter for now. ![]() Retrofit 2 now supports many different parsers for processing network response data, including Moshi, a library build by Square for efficient JSON parsing. In the past, Retrofit relied on the Gson library to serialize and deserialize JSON data. Retrofit 2.2 and newer have a first-party call adapter for RxJava 2:( ) Implementation '2:adapter-rxjava:2.1.0 ' This is now DEPRECATED !Īdapter-rxjava is now deprecated. Implementation 'io.reactivex:rxandroid:1.2.1 ' This interface contains the endpoints used in the application.Implementation 'io.reactivex:rxjava:1.1.6 ' My question is, how would I use RxJava to make multiple calls using data for the list of movie titles of unknown size (which I can pass to getAndDisplayImage instead of a single string)? I have made several attempts but none seem to work for my use case. List listingImages = void onFailure(Call call, Throwable t) ListingImageApiService listingImageApiService = retrofit2.create(ListingImageApiService.class) Ĭall call = listingImageApiService.getListingImages(search) Public void getAndDisplayImage(String search) The code i'm using for a single call is: public interface getListingImages String term) ![]() I've tried using RxJava code found elsewhere on the internet but none of it seems to work as I don't have prior knowledge of how many calls I will be making or what the search term will be. I know how to call the API for a single image, but I don't know how to make multiple calls. I then want to call a different API (contextual web search) to display an image of a relevant movie poster (just for a nice visual effect) for each movie listing. tAdapter(new void onFailure(Call call, Throwable t) List listings = response.body().getListings() ListingApiService listingApiService = retrofit.create(ListingApiService.class) Ĭall call = listingApiService.getShowtimes(id) Ĭall.enqueue(new Callback() void onResponse(Call call, Response response) addConverterFactory(GsonConverterFactory.create()) Public void connectAndGetApiData(String id) public interface getShowtimes String id) I then use the cinema id which the user clicks on to display showtimes for this cinema i.e. I begin by calling an API using retrofit to show cinemas near a users location. I'm currently trying to use RxJava with Retrofit for the first time but can't seem to get anything working for my specific use case:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |