Main Tutorials

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 Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
10 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
benny
5 years ago

@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
8 years ago

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
8 years ago

not working man help me.

pankui
8 years ago

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

thili
8 years ago

not working

Matthew Ong
8 years ago

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
9 years ago

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!

praveen
10 years ago

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
11 years ago

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
11 years ago
Reply to  Diganta

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