Search code examples
androidretrofit2android-youtube-apiyoutube-data-api

Youtube API with Retrofit2 not able to parse response(Error: PlaylistItemListResponse has type PageInfo got LinkedHashMap)


I am trying to use Youtube API with Retrfoit2 on Android but both Jackson/JSON converters are not able to parse objects.

YoutubeService

public interface YoutubeService {
    @GET("playlistItems?part=snippet%2CcontentDetails")
    Observable<PlaylistItemListResponse> getVideos(@Query("maxResults") Integer maxResults,
                                               @Query("pageToken")String pageToken,
                                               @Query("playlistId")String playlistId,
                                               @Query("key")String key);
}

Here is how I am using it:

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(YouTube.DEFAULT_BASE_URL)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(JacksonConverterFactory.create())
            .build();
    youtubeService = retrofit.create(YoutubeService.class);

Below is the error I am getting:

reactivex.exceptions.OnErrorNotImplementedException: field com.google.api.services.youtube.model.PlaylistItemListResponse.pageInfo has type com.google.api.services.youtube.model.PageInfo, got java.util.LinkedHashMap (through reference chain: com.google.api.services.youtube.model.PlaylistItemListResponse["pageInfo"])

This is model for PlaylistItemResponse

Java files for PlaylistItemResponse

This is response

Can someone guide me how to solve this?


Solution

  • I can't understand deeper with your problem but try to change like below.

    1.Make it With Gson

    addConverterFactory(GsonConverterFactory.create(gson))

    2.change your model class PlaylistItemListResponse with below.

    Link of model class

    because its all about your model class issue.

    Happy coding