Retrofit: xml & json converter

Created on 6 Apr 2016  路  1Comment  路  Source: square/retrofit

i'm comfusing with using multi converter.
in my case, i have some intf reqeust&response through json, and other intf through xml.
i add the simpleXmlConverter first then jacksonConverter, but the jackson one seems not work.
if i change the sequence, the xml not work.
what's wrong and how to solve this?

mRetrofit = new Retrofit.Builder().addConverterFactory(JacksonConverterFactory.create(mapper)) .addConverterFactory(SimpleXmlConverterFactory.create()).baseUrl(API_HOST).client(client).build();

Most helpful comment

Both of the JSON and XML converters attempt to handle all types so whichever comes first will try to serialize everything. You need to instruct Retrofit to choose the right one. There is a sample which shows how to do this: https://github.com/square/retrofit/blob/9de61e0672ab0468d42bceb536db55007821769d/samples/src/main/java/com/example/retrofit/JsonAndXmlConverters.java

>All comments

Both of the JSON and XML converters attempt to handle all types so whichever comes first will try to serialize everything. You need to instruct Retrofit to choose the right one. There is a sample which shows how to do this: https://github.com/square/retrofit/blob/9de61e0672ab0468d42bceb536db55007821769d/samples/src/main/java/com/example/retrofit/JsonAndXmlConverters.java

Was this page helpful?
0 / 5 - 0 ratings