RESTEasy – Could not find MessageBodyWriter for response object of type:xx of media type: application/xml

Problem

Developing RESTEasy + JAXB provider to support XML, when return it back to client, it prompts following error message :

org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: 
	Could not find MessageBodyWriter for response object of type: 
                com.mkyong.rest.User of media type: application/xml
 
    at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:500)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
    //...

Solution

To use JAXB in RESTEasy, you need to include “resteasy-jaxb-provider.jar“.

  <repositories>
	<repository>
		<id>JBoss repository</id>
		<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
	</repository>
  </repositories>
 
  <dependencies>
 
	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-jaxrs</artifactId>
		<version>2.2.1.GA</version>
	</dependency>
 
	<dependency>
		<groupId>org.jboss.resteasy</groupId>
		<artifactId>resteasy-jaxb-provider</artifactId>
		<version>2.2.0.GA</version>
	</dependency>
 
  </dependencies>
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • Pingback: pay per day loan plans()

  • Pingback: stop parking()

  • Pingback: alkaline water()

  • Pingback: stop parking()

  • Pingback: laan penge()

  • Pingback: mobile porn()

  • Pingback: lan her og nu()

  • Pingback: Website()

  • Pingback: tvpackages.net()

  • Pingback: DIRECTV for your company()

  • Pingback: watch movies online free()

  • Pingback: Blue Coaster33()

  • Pingback: JAX-RS TUTORIALS | BUYWORKSELL()

  • praveen

    After Adding resteasy-jaxb-provider.jar File also i could see below Exception

    //Exception

    HTTP Status 500 – Could not find MessageBodyWriter for response object of type: com.mkyong.rest.Product of media type: application/json

  • Diganta

    Receiving the following error

    java.lang.RuntimeException: could not find writer for content-type application/json type: java.lang.String
    at org.jboss.resteasy.client.ClientRequest.writeRequestBody(ClientRequest.java:409)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor$ClientRequestEntity.(ApacheHttpClientExecutor.java:117)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.loadHttpMethod(ApacheHttpClientExecutor.java:188)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.execute(ApacheHttpClientExecutor.java:56)
    at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:378)
    at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:590)
    at org.jboss.resteasy.client.ClientRequest.post(ClientRequest.java:496)
    at org.jboss.resteasy.client.ClientRequest.post(ClientRequest.java:501)
    at com.resteasy.RESTEasyClientPost.main(RESTEasyClientPost.java:24)

    • priya vincent

      still i face the linkage problem, after i add the resteasy-jaxb-provider also

      java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/projects/jaxb/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RESTfulExample/WEB-INF/lib/jaxb-impl-2.1.12.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)

  • Pingback: JAX-RS Tutorial()