I have a problem with retrofit and XML, I use SimpleXmlConverterFactory, and I have this error : Caused by: "java.lang.IllegalArgumentException: Could not locate ResponseBody converter for java.util.List.
Tried:
* retrofit2.BuiltInConverters * retrofit2.converter.simplexml.SimpleXmlConverterFactory"
gradle:
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:okhttp:3.9.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
compile ('com.squareup.retrofit2:converter-simplexml:2.3.0') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
service :
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL)
.client(buildHttpClient())
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
private OkHttpClient buildHttpClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return (new OkHttpClient.Builder())
.addInterceptor(buildDefaultHeadersInterceptor())
.addNetworkInterceptor(buildLogInterceptor())
.build();
}
model :
@Root(name = "item")
public class Item {
@Element(name = "link")
private String link;
@Element(name = "title")
private String title;
@Element(name = "description")
private String description;
public Item() {}
}
xml :
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel xml:lang="fr">
<title>...</title>
<link>http://www.jouars-pontchartrain.fr/</link>
<description>...</description>
<language>fr</language>
<generator>SPIP - www.spip.net</generator>
<image>...</image>
<item xml:lang="fr">
<title>
title here
</title>
<link>
link here
</link>
<description>
description here
</description>
</item>
<item xml:lang="fr">...</item>
<item xml:lang="fr">...</item>
<item xml:lang="fr">...</item>
<item xml:lang="fr">...</item>
</channel>
</rss>