Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-158

No MessageBodyWriter for a Collection or an array as returned object

    Details

    • Type: Feature Request
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: Beta 8
    • Fix Version/s: Beta 9
    • Component/s: jaxrs
    • Labels:
      None
    • Environment:

      Windows, tomcat, java 6

      Description

      Using the built-in JAXB/JSON providers and the following classes;

      @Path( "/principals" )
      @Produces( "application/xml" )
      public interface Admin
      {
      @GET
      @Path( "/user" )
      public User[] getUsers();
      }

      @XmlRootElement
      public class User
      {
      @XmlAttribute
      private Integer id;

      @XmlElement
      private String name;
      }

      I got the following error:
      41548 [http-8080-2] ERROR org.jboss.resteasy.core.SynchronousDispatcher - Failed executing GET principals/user
      org.jboss.resteasy.spi.LoggableFailure: Could not find MessageBodyWriter for response object of type: [LUser; of media type: application/xml
      at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:422)
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:357)
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:182)
      at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:90)
      at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:66)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      ...

      This is because the built-in JAXB providers are only isReadWritable for either JAXBElement class or @XmlRoolElement and @XmlType annotations. Same error if the returned type is a collection.

      There ought to be an easier way then writing one's own MessageBodyWriter for that.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                bill.burke Bill Burke
                Reporter:
                mrhai Hai Nguyen
              • Votes:
                1 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: