Could not find MessageBodyWriter for response object of type
lowecg2004 Nov 18, 2008 3:13 AMHello all,
I'm trying to get a rest easy service to serve JSON and I'm having a problem with returning a simple POJO. I get the following exception:
01:56:12,040 ERROR [STDERR] java.lang.RuntimeException: Could not find MessageBodyWriter for response object of type: class [Lcom.site.session.rest.Book; of media type: application/json 01:56:12,040 ERROR [STDERR] at org.resteasy.ResourceMethod.writeResponse(ResourceMethod.java:218) 01:56:12,040 ERROR [STDERR] at org.resteasy.ResourceMethod.invoke(ResourceMethod.java:198) 01:56:12,040 ERROR [STDERR] at org.resteasy.ResourceMethod.invoke(ResourceMethod.java:134) 01:56:12,040 ERROR [STDERR] at org.resteasy.Dispatcher.invoke(Dispatcher.java:161) 01:56:12,040 ERROR [STDERR] at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:127) 01:56:12,040 ERROR [STDERR] at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:71) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80) 01:56:12,041 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 01:56:12,041 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 01:56:12,041 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73) 01:56:12,041 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177) 01:56:12,041 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267) 01:56:12,041 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380) 01:56:12,041 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) 01:56:12,041 ERROR [STDERR] at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) 01:56:12,041 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 01:56:12,041 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 01:56:12,041 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) 01:56:12,041 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 01:56:12,042 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432) 01:56:12,042 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 01:56:12,042 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 01:56:12,042 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) 01:56:12,042 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 01:56:12,042 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) 01:56:12,042 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) 01:56:12,042 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
Here is my test code:
@Path("/testService") @Name("testServiceRest") @Scope(ScopeType.STATELESS) @ConsumeMime({"application/json"}) @ProduceMime({"application/json"}) public class TestServiceRest { @GET @Path("/getBooks") public Book[] getBooks() { final Book[] result = new Book[1]; result[0] = new Book("Author", "ISBN", "Title"); return result; } } ... import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "book") public class Book { private String author; private String ISBN; private String title; public Book() { } public Book(String author, String ISBN, String title) { this.author = author; this.ISBN = ISBN; this.title = title; } @XmlElement public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } @XmlElement public String getISBN() { return ISBN; } public void setISBN(String ISBN) { this.ISBN = ISBN; } @XmlAttribute public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
As I understood it, I thought Seam would marshal JSON out of the box. I've left the resteasy:application-config with all the defaults.
Am I missing something or have I completely got this wrong?! I'd be grateful for a couple of pointers, I've search high and low for an answer to this and I've now reached a dead end.
Cheers,
Chris.
BTW - I'm using Seam 2.1.0.GA.