Note that there are some explanatory texts on larger screens.

plurals
  1. POintegrating Swagger with JAX-RS and JAXB help needed
    text
    copied!<p>I'm working on REST Api using JAX-RS and JAXB. I also would like to use Swagger to generate docs for the api. I followed the example here <a href="https://github.com/wordnik/swagger-core/wiki/java-jax-rs" rel="nofollow">https://github.com/wordnik/swagger-core/wiki/java-jax-rs</a> . So I have added com.wordnik.swagger.jaxrs.listing to init parameters in web.xml as below:</p> <pre><code>&lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;com.api.resources;com.api;com.wordnik.swagger.jaxrs.listing;&lt;/param-value&gt; &lt;/init-param&gt; </code></pre> <p>When I tray to access the localhost:9090/rapi/api-docs.json url I get the following error:</p> <pre><code>SEVERE: Mapped exception to response: 500 (Internal Server Error) javax.ws.rs.WebApplicationException: javax.xml.bind.JAXBException: class com.wordnik.swagger.core.Documentation nor any of its super class is known to this context. at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:159) at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1451) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:324) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488) Caused by: javax.xml.bind.JAXBException: class com.wordnik.swagger.core.Documentation nor any of its super class is known to this context. at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:611) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:486) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:320) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:177) at com.sun.jersey.json.impl.BaseJSONMarshaller.marshallToJSON(BaseJSONMarshaller.java:103) at com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.writeTo(JSONRootElementProvider.java:143) at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:157) </code></pre> <p>I fixed it by adding com.wordnik.swagger.core to my custom JAXBContextProvider as below:</p> <pre><code>public JAXBContextProvider() throws JAXBException { this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), "com.api.model.impl.v1:com.api.resource.framework:com.wordnik.swagger.core"); } </code></pre> <p>This caused another error:</p> <pre><code>SEVERE: The provider class, class comapi.JAXBContextProvider, could not be instantiated. Processing will continue but the class will not be utilized javax.xml.bind.JAXBException: "com.wordnik.swagger.core.Documentation" doesnt contain ObjectFactory.class or jaxb.index </code></pre> <p>I have been using jaxb.index files to keep the context aware of the classes with JAXB annotations, however there is no jaxb.index file in swagger package which inludes the Documentation class. Has anyone come across similar issue when integrating Swagger with JAXB and JAX-RS?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload