question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JAXB - Unable to create converter for class ...

See original GitHub issue

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 ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
Orbytcommented, Mar 21, 2018

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

6reactions
Orbytcommented, Mar 20, 2018

@JakeWharton @swankjesse Why has the Simple XML converter been deprecated in favor of the JAXB converter if JAXB is not compatible?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to create converter for my class in Android Retrofit library
Im migrating from using Volley to Retrofit, I already have gson class that I used before for converting JSONObject reponse to ...
Read more >
Retrofit java.lang.IllegalArgumentException: Unable to create ...
IllegalArgumentException: Unable to create converter for class … Make sure your JSON fields in your api service interface not duplicated.
Read more >
Why I get Unable to create converter exception from retrofit?
Finally I found the issue, I made a mistake, because I tried to use suspend fun and retrofit Call at the same time....
Read more >
JAXBContext (Java Platform SE 7 ) - Oracle Help Center
It does not apply to JAXB annotated classes. JAXB Providers must generate a jaxb.properties file in each package containing schema derived classes.
Read more >
Using Retrofit 2.x as REST client - Tutorial - Vogella.com
Besides the listed converters, you can also create custom converters to process other protocols by subclassing the Converter.Factory class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found