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. 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
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 […]

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)

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

trackback
JAX-RS TUTORIALS | BUYWORKSELL

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

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!

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

thili
Guest
thili

not working

pankui
Guest
pankui

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

thili
Guest
thili

not working man help me.

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

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.