简体   繁体   中英

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

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?...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM