Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JAXB with Retrofit instead of SimpleXml

According to the 2.4.0 update of Retrofit:

New: Converter for JAXB replaces the now-deprecated converter for Simple XML Framework.

I haven't found a single tutorial on how to implement this to replace my simple xml annotated pojos.

Can anyone share a quick guide on how to transition from simplexml to jaxb?

like image 905
usernotnull Avatar asked Apr 06 '18 19:04

usernotnull


2 Answers

I have been googling for this today, and eventually ended up on the retrofit JAXB Github page, where they politely tell us that JAXB does not work on Android:

Note that JAXB does not work on Android.

Then I found this answer, where they provide a workaround for this problem.

Please note that I have not tested this myself as I am in a similar situation as you. Trying to figure it all out when I stumbled upon your question. Hope this helps! :)

like image 65
Abby Avatar answered Oct 21 '22 04:10

Abby


You can add like this

Add the dependency in the app-level Gradle.

implementation 'com.squareup.retrofit2:retrofit:2.7.2' (Latest version)

 Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(BuildConfig.BASE_URL)
                    .addConverterFactory(JaxbConverterFactory.create())
                    .client(httpClient.build())
                    .build();

But this will not work with your existing SimpleXmlFactory

like image 1
Saurabh Srivastava Avatar answered Oct 21 '22 04:10

Saurabh Srivastava