Hello,
I am using the newly version retrofit 2.4.0 with the new jaxb converter
implementation "com.squareup.retrofit2:converter-jaxb:2.4.0"
And I got the following exception when I call my webservice :
java.lang.IllegalArgumentException: Unable to create converter for class xxx.oym.autocomplete.OymAutocompleteResult
for method OymWS.getAutocomplete
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:755)
at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:741)
Caused by: java.lang.IllegalArgumentException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: Didn't find class "com.sun.xml.internal.bind.v2.ContextFactory" on path: DexPathList[[...]]]
at retrofit2.converter.jaxb.JaxbConverterFactory.contextForType(JaxbConverterFactory.java:76)
at retrofit2.converter.jaxb.JaxbConverterFactory.responseBodyConverter(JaxbConverterFactory.java:67)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330)
at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313)
at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:739)
... 12 more
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: Didn't find class "com.sun.xml.internal.bind.v2.ContextFactory" on path: DexPathList[[...]]]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:241)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:477)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
at retrofit2.converter.jaxb.JaxbConverterFactory.contextForType(JaxbConverterFactory.java:74)
... 16 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.xml.internal.bind.v2.ContextFactory" on path: DexPathList[[...]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:594)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:239)
So I added dependency to com.sun.xml.bind:jaxb-impl:2.2.11 which lead to another exception :
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.xml.bind.Util" on path: DexPathList[[...]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
And finally I added the dependency to com.sun.xml.bind:jaxb-core:2.2.11 and it drives to a dead-end with the following error :
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Image;
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:381)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:63)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:128)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:84)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:162)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:92)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:444)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:292)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:139)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1138)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:162)
at java.lang.reflect.Method.invoke(Native Method)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:262)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:249)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:456)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
at retrofit2.converter.jaxb.JaxbConverterFactory.contextForType(JaxbConverterFactory.java:74)
at retrofit2.converter.jaxb.JaxbConverterFactory.responseBodyConverter(JaxbConverterFactory.java:67)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330)
However when I launch my Junit tests with MockWebServer for the given webservice all is doing fine (probaly all the class are shipped in java junit)
Is there a documentation to how use the JAXB converter on android ?
I'm not sure if JAXB works on Android. The last time I tried was 7 years ago and I'm fairly confident that I got it working but I don't recall any of the details.
Maybe you want to try https://github.com/Tickaroo/tikxml instead?
Closing since this is a usage problem of JAXB and not specific to the Retrofit converter.
@JakeWharton @swankjesse Why has the Simple XML converter been deprecated in favor of the JAXB converter if JAXB is not compatible?
Retrofit is not an Android-specific library.
@JakeWharton Of course, but it is heavily used in many Android applications. I do not see any other Retrofit supported XML converters, so dropping Simple XML in favor of something that may not work on Android seems strange.
I understand the option to fork and maintain the Simple XML converter exists, but do you have any other recommendations, other than TikXML, for those who would like to use Retrofit with services utilizing XML?
You can also continue to use Simple XML. Deprecated does not mean
un-functional. We just don't recommend it because it's a mess of a library
that isn't maintained and has security vulnerabilities.
On Tue, Mar 20, 2018 at 8:02 PM Caleb Chiesa notifications@github.com
wrote:
@JakeWharton https://github.com/jakewharton Of course, but it is
heavily used in many Android applications. I do not see any other Retrofit
supported XML converters, so dropping Simple XML in favor of something that
may not work on Android seems strange.I understand the option to fork and maintain the Simple XML converter
exists, but do you have any other recommendations, other than TikXML
https://github.com/Tickaroo/tikxml, for those who would like to use
Retrofit with services utilizing XML?—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/2702#issuecomment-374798127,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEfFdF8JNnbdmyeI8F4A4E7sjma28ks5tgZiOgaJpZM4SwWMb
.
@JakeWharton @swankjesse Thank you.
Most helpful comment
@JakeWharton Of course, but it is heavily used in many Android applications. I do not see any other Retrofit supported XML converters, so dropping Simple XML in favor of something that may not work on Android seems strange.
I understand the option to fork and maintain the Simple XML converter exists, but do you have any other recommendations, other than TikXML, for those who would like to use Retrofit with services utilizing XML?