我正在使用 Retrofit 2.0-beta1。如何发出简单的同步请求并将 JSON 响应反序列化为 POJO 列表?这是我的界面:
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);
}
}
但我收到此错误:
> Unable to create call adapter for
> java.util.List<com.bla.bla.rest.resources.ArticleResource>
改造建造
Retrofit retrofit = (new Retrofit.Builder()).baseUrl(this.baseUrl).build();
ArticlesAPI api = retrofit.create(ArticlesAPI.class);
如果您使用的是kotlin
coroutines
并且函数不是suspend
功能
public interface ArticlesAPI {
@GET("url.../habits/progress/")
suspend fun getHabitsTasks(): BaseResponse<HabitResModel>
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)