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

No MessageBodyWriter for a Collection or an array as returned object

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Done
    • Major
    • Beta 9
    • Beta 8
    • jaxrs
    • None

    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.

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            mrhai Hai Nguyen (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: