Problems integrating Simple XML Converter into Android version

I ran into two problems when integrating a Simple XML Converter into a modification for Android.
1). I received a compilation error after adding "compile (" com.squareup.retrofit: converter-simplexml: 1.9.0 ") to build.gradle.

Error Report: Information: Gradle Tasks [: app: assembleDebug] Warning. The xpp3: xpp3: 1.1.3.3 dependency is ignored for debugging, as it may conflict with the internal version provided by Android. In case of a problem, repack it with jarjar to change the class packages Warning: The xpp3: xpp3: 1.1.3.3 dependency is ignored for release, as this may contradict the internal version provided by Android. If a problem occurs, repack it with jarjar to modify the class packages.

2). I created Java Schemas using this http://pojo.sodhanalibrary.com/Convert by providing the root class name. And I keep getting InstantiateException or ElementException for one or the other element and mazorly retrofit.converter.ConversionException: org.simpleframework.xml.core.ValueRequiredException: cannot satisfy @ org.simpleframework.xml.Element (data = false, name = description, required = true, type = void) in the "description" field. The same error for many fields.

+5
source share
1 answer

ISSUE 1).
I had to add the following to my build.gradle. Since these packages come with Android already, so there were problems.

compile ('com.squareup.retrofit:converter-simplexml:1.9.0') { exclude group: 'xpp3', module: 'xpp3' exclude group: 'stax', module: 'stax-api' exclude group: 'stax', module: 'stax' } 

ISSUE 2).
I had to have a Java class hierarchy, which should start with the first element that is in XML. I had "Rss" as the first element in my XML. And although I generated the schemas using http://pojo.sodhanalibrary.com/Convert , I gave my name, something like "Warnings", which generated classes for all the necessary elements. Warnings.java had an instance of "Rss". Instead of skipping Rss, I passed Warnings for an upgrade.

 Class Warnings { private Rss rss; ..... ..... } Class Rss { private Channel channel; ..... ..... } 

To some extent, he can find the class hierarchy, but he began to give the errors / exceptions mentioned in the question for all fields of all classes, although they seem to be available. After quite a bit of time spent fixing these errors, I changed the response class that was passed to retrofit.Callback from Warnings to Rss, and it worked.

XML:

 <rss version="2.0"> <channel>...</channel> </rss> 

This was my modification request code with errors:

 retrofitService.getWarnings(lat, lon, authKey, new Callback<Warnings>() { @Override public void success(WarningsResponse warningsResponse, Response response) { // handle success response.. } @Override public void failure(RetrofitError error) { // handle error response } }); 

Work code:

 retrofitService.getWarnings(lat, lon, authKey, new Callback<Rss>() { @Override public void success(WarningsResponse warningsResponse, Response response) { // handle success response.. } @Override public void failure(RetrofitError error) { // handle error response } }); 

The only diff is the class passed in for the callback.

So, use the root element class name in XML to jump to the callback so that the conversion of XML objects to Java is easily successful.

You can find this discussion in XML integration using the Retrofit help site:
https://futurestud.io/blog/retrofit-how-to-integrate-xml-converter/

+12
source

All Articles