What kind of XmlConverter can I use for Retrofit in Android?

4.2k Views Asked by At

I am developing an Android app using Retrofit.

The server is sending XML as a response. So I should convert it. In the case of the Json, I used the GsonConverter. And for XMl, I think I can use SimpleXMLConverter.

I visited the GitHub link for SimpleXMLConverter: https://github.com/square/retrofit/tree/master/retrofit-converters/simplexml

And I found this message:

Deprecated – Please switch to the JAXB Converter

So I visited the Github link for JAXBConverter: https://github.com/square/retrofit/tree/master/retrofit-converters/jaxb

But I found this message:

Note that JAXB does not work on Android.

Hmm... what xml converter should I used?...

2

There are 2 best solutions below

4
Alexander On

I was facing the same issue, but Jake Wharton came to the rescue.
(https://github.com/square/retrofit/issues/2733)

Tickaroo TikXML can be used as an alternative
add the following dependencies

implementation 'com.tickaroo.tikxml:annotation:0.8.15'
implementation 'com.tickaroo.tikxml:core:0.8.15'
implementation 'com.tickaroo.tikxml:retrofit-converter:0.8.15'

annotationProcessor 'com.tickaroo.tikxml:processor:0.8.15'

(if you have problems with the version you can use 0.8.13)

After you've synced your project you're able to use the TikXML converter factory like so:

 Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
                .addConverterFactory(TikXmlConverterFactory.create())
                .build();

The read me documentation of TikXML is pretty straight forward and can be found here: https://github.com/Tickaroo/tikxml/blob/master/docs/AnnotatingModelClasses.md

But if you need more help please let me know

1
free On

Please try SimpleXMLConverter even if it is deprecated