我想在Android上使用Youtube API與Retrfoit2,但Jackson/JSON轉換器都無法解析對象。Youtube API與Retrofit2無法解析響應(錯誤:PlaylistItemListResponse類型PageInfo得到LinkedHashMap)
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);
}
下面是我使用它:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(YouTube.DEFAULT_BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(JacksonConverterFactory.create())
.build();
youtubeService = retrofit.create(YoutubeService.class);
下面是我得到的錯誤:
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是模型PlaylistItemResponse
的Java files爲PlaylistItemResponse
This是響應
有人能指導我如何解決這個問題?
你試過用'.addConverterFactory(GsonConverterFactory.create())'傑克遜一個呢?因爲谷歌有時創建他們的類與Gson專門工作 – MatPag
是的,我試過,但也完全相同的錯誤 – bpsingh
canu plz把你的模型類 PlaylistItemListResponse?完整的java文件 –