Retrofit 2.0:无法为类创建呼叫适配器 [英] Retrofit 2.0: Unable to create call adapter for class

查看:84
本文介绍了Retrofit 2.0:无法为类创建呼叫适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Retrofit 2.0-beta1.如何发出简单的同步请求并将JSON响应反序列化为POJO列表?这是我的界面:

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();
}

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);

推荐答案

根据您发布的代码,您必须更改为

Accordingly to the code you posted you have to change from

List<ArticleResource> getArticles();

Call<List<ArticleResource>> getArticles();

您可能还想显式调用addConverterFactory来设置要使用的转换器

You might also want to call explicitly addConverterFactory to set the converter you want to use

这篇关于Retrofit 2.0:无法为类创建呼叫适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆