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>

About the Author

author image
mkyong
Founder of Mkyong.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

avatar
11 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
9 Comment authors
bennyPhumipat SukpimontreepankuithiliMatthew Ong Recent comment authors
newest oldest most voted
benny
Guest
benny

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)

adding those annotations to specify what I want produce did the trick, provided that you have the correct dependencies.

Phumipat Sukpimontree
Guest
Phumipat Sukpimontree

for new resteasy version 3.x.x use “resteasy-jettison-provider” and older use “resteasy-jaxb-provider” example mydependency org.jboss.resteasy resteasy-jettison-provider 3.0.11.Final you can remove @BadgerFish if you want original JSON style and you can add it if you like BadgerFish this style {“book”: { “@title”:”EJB 3.0″, “author”:{“$”:”Bill Burke”}, “ISBN”:{“$”:”596529260″} } } @ ==> @XmlAttribute $ ==> @XmlElement I read from this document and then try, It’s works! REF : https://docs.jboss.org/resteasy/docs/3.0.13.Final/userguide/html_single/#JAXB_+_JSON_provider

thili
Guest
thili

not working man help me.

pankui
Guest
pankui

?? ???????jsonp ? jersey ?? ??json ?????????ajax ?? ?

thili
Guest
thili

not working

Matthew Ong
Guest
Matthew Ong

Hi,

Could you please help why this is still an issue?
http://stackoverflow.com/questions/30616954/resteasy-3-0-9-final-nomessagebodywriterfoundfailure

NoMessageBodyWriterFoundFailure

Maven Sample project can be downloaded here, link expires on June 10, 2015 :
https://www.hightail.com/download/bXBaTXRSSU9LVld4djlVag

Colin
Guest
Colin

I was scratching my head on this one for awhile until I stumbled across your post, and discovered I had forgotten to include a bunch of resteasy jars in my classpath, one of which was the jar you mention above. Thanks!

trackback
JAX-RS TUTORIALS | BUYWORKSELL

[…] RESTEasy – Could not find MessageBodyWriter for response object of type:xx of media type: applicat… […]

praveen
Guest
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
Guest
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
Guest
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/)

trackback
JAX-RS Tutorial

[…] – Could not find message body reader for type: multipart/form-dataRESTEasy – Could not find MessageBodyWriter for response object of type:xx of media type: applicat…Illegal to inject a message body into a singleton into public […]