title: Consume application/json in REST services using Jersey in Osgi
body: <p>I'm deploying some REST services in an Osgi bundle using Jersey. The services are notated like </p>
  
  <pre><code>@POST
  @Path("/adduser")
  @Consumes(MediaType.APPLICATION_XML+","+MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_XML)
  public Message addUser(User user) {
   ...
  }
  </code></pre>
  
  <p>The first problem I have is that the service doesn't accept both of the MIME types I put into the @Consumes notation but just the first one.</p>
  
  <p>The second and worst is that receive the following exeception when I try to call to the services. I can @Consumes text/plain and I can @Produces application/xml for example but if I try to @Consumes an application/json or application/xml the server throw the exception.</p>
  
  <p>The exception is throwed when I make the call with a wellformed json or xml using a REST client or an ajax call, if the service just receive text/plain or doesnt receive anything the response to the client is made correctly in xml so the serializer is working ok when I send POJO's but not receiving them.</p>
  
  <pre><code> javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.xml.bind.Unmarshaller.unmarshal(Ljavax/xml/transform/Source;)Ljava/lang/Object;" the class loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) of the current class, org/glassfish/jersey/message/internal/XmlRootElementJaxbProvider, and the class loader (instance of &lt;bootloader&gt;) for resolved class, javax/xml/bind/Unmarshaller, have different Class objects for the type ject; used in the signature
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:353)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
      at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:96)
      at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:79)
      at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at es.upm.cedint.gateway.api.corssupport.CORSFilter.doFilter(CORSFilter.java:164)
      at es.upm.cedint.gateway.api.corssupport.CORSFilter.doFilter(CORSFilter.java:246)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at es.upm.cedint.gateway.api.security.SecurityFilter.doFilter(SecurityFilter.java:87)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:48)
      at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:39)
      at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:326)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
  
  Caused by: org.glassfish.jersey.server.ContainerException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.xml.bind.Unmarshaller.unmarshal(Ljavax/xml/transform/Source;)Ljava/lang/Object;" the class loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) of the current class, org/glassfish/jersey/message/internal/XmlRootElementJaxbProvider, and the class loader (instance of &lt;bootloader&gt;) for resolved class, javax/xml/bind/Unmarshaller, have different Class objects for the type ject; used in the signature
      at org.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:230)
      at org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:212)
      at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:401)
      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:243)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:322)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:211)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:979)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:344)
      ... 36 more
  
  Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.xml.bind.Unmarshaller.unmarshal(Ljavax/xml/transform/Source;)Ljava/lang/Object;" the class loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) of the current class, org/glassfish/jersey/message/internal/XmlRootElementJaxbProvider, and the class loader (instance of &lt;bootloader&gt;) for resolved class, javax/xml/bind/Unmarshaller, have different Class objects for the type ject; used in the signature
          at org.glassfish.jersey.message.internal.XmlRootElementJaxbProvider.readFrom(XmlRootElementJaxbProvider.java:140)
          at org.glassfish.jersey.message.internal.AbstractRootElementJaxbProvider.readFrom(AbstractRootElementJaxbProvider.java:122)
          at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:181)
          at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134)
          at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:72)
          at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134)
          at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:988)
          at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:833)
          at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:252)
          at org.glassfish.jersey.server.internal.inject.EntityParamValueFactoryProvider$EntityValueFactory.get(EntityParamValueFactoryProvider.java:96)
          at org.glassfish.jersey.server.internal.inject.AbstractHttpContextValueFactory.provide(AbstractHttpContextValueFactory.java:66)
          at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:81)
          at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:121)
          at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:195)
          at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:94)
          at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:353)
          at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:343)
          at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
          at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:237)
          ... 45 more
  </code></pre>
  
  <p>Anyone have any idea of what could be wrong?</p>
  
  <p>PD:I have @XMLRootElement at the begining of the User class that I want to serialize and the server I use is Jetty.</p>