Reputation: 141
Im using Retrofit2 converter-simplexml library,the code run successful when I using converter-gson,but when I add simplexmlConverter,I got a exception:
java.lang.IllegalArgumentException: Unable to create converter for java.util.List<com.rengwuxian.rxjavasamples.model.ZhuangbiImage>
Caused by: java.lang.IllegalArgumentException: Could not locate ResponseBody converter for java.util.List<com.rengwuxian.rxjavasamples.model.ZhuangbiImage>.
This is where I am trying to execute the retro http request:
private void search(String key) {
subscription = getZhuangbiApi()
.search(key)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(observer);
}
public static ZhuangbiApi getZhuangbiApi() {
if (zhuangbiApi == null) {
Retrofit retrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(baseUrl)
.addConverterFactory(simpleXmlConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.build();
zhuangbiApi = retrofit.create(ZhuangbiApi.class);
}
return zhuangbiApi;
}
My interface which turned to be my API
public interface ZhuangbiApi {
@GET("merchant/list")
Observable<List<ZhuangbiImage>> search(@Query("app_code") String appCode);
}
And the ZhuangbiImage class
@Root(name = "item")
public class ZhuangbiImage {
@Element(name = "title")
public String title;
@Element(name = "merchant_id")
public String merchantId;
}
Upvotes: 14
Views: 6746
Reputation: 1594
XML can only be deserialized to a concrete type and not a list of types like JSON. In this case, the body type should represent the <rss>
tag and its children and not List<ZhuangbiImage>
.
More details from official retrofit team Retrofit, XML and SimpleXmlConverterFactory problem
Upvotes: 1
Reputation: 7010
You have to check your dependencies in gradle-file. Also check that the version of retrofit and converter is the same.
Upvotes: 0