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.