Unable to create call adapter for class example.Simple

后端 未结 14 1125
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 23:14

I am using retrofit 2.0.0-beta1 with SimpleXml. I want the retrieve a Simple (XML) resource from a REST service. Marshalling/Unmarshalling the Simple object with SimpleXML w

相关标签:
14条回答
  • 2020-12-04 23:47
    public interface SimpleService {
    
      @GET("/simple/{id}")
      Simple getSimple(@Path("id") String id);
    
    }
    

    Communication with the network is done with the separate thread so you should change your Simple with that.

    public interface SimpleService {
    
      @GET("/simple/{id}")
      Call<Simple> getSimple(@Path("id") String id);
    
    }
    
    0 讨论(0)
  • 2020-12-04 23:50

    Short answer: return Call<Simple> in your service interface.

    It looks like Retrofit 2.0 is trying to find a way of creating the proxy object for your service interface. It expects you to write this:

    public interface SimpleService {
        @GET("/simple/{id}")
        Call<Simple> getSimple(@Path("id") String id);
    }
    

    However, it still wants to play nice and be flexible when you don't want to return a Call. To support this, it has the concept of a CallAdapter, which is supposed to know how to adapt a Call<Simple> into a Simple.

    The use of RxJavaCallAdapterFactory is only useful if you are trying to return rx.Observable<Simple>.

    The simplest solution is to return a Call as Retrofit expects. You could also write a CallAdapter.Factory if you really need it.

    0 讨论(0)
提交回复
热议问题