I'm using Retrofit 2.0-beta1. How can I make a simple synchronous request and deserialize a JSON response as a POJO list? This is my interface:
public interface ArticlesAPI {
@GET("/articles")
List<ArticleResource> getArticles();
}
and
public class ArticleResource {
public String id;
public String name;
public Article toArticle() {
return new Article(id, name);
}
}
but I get this error:
> Unable to create call adapter for > java.util.List<com.bla.bla.rest.resources.ArticleResource>
Retrofit build
Retrofit retrofit = (new Retrofit.Builder()).baseUrl(this.baseUrl).build();
ArticlesAPI api = retrofit.create(ArticlesAPI.class);
This issue can also occur if you are using kotlin
coroutines
and the function is not suspend
function
public interface ArticlesAPI {
@GET("url.../habits/progress/")
suspend fun getHabitsTasks(): BaseResponse<HabitResModel>
}
Accordingly to the code you posted you have to change from
List<ArticleResource> getArticles();
to
Call<List<ArticleResource>> getArticles();
You might also want to call explicitly addConverterFactory
to set the converter you want to use
在 build.gradle 文件中将 retrofit2 版本更改为最新版本
implementation "com.squareup.retrofit2:retrofit:2.9.0"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.