Why "invalid request" when requesting resource with mime type application/xml in Jersey?
In our application there is a working method that returns a JSON representation of Company. I modified @Produces by adding MediaType.APPLICATION_XML. However, when I set the "Accept" header in the request to "application/xml", Jersey returns a 400 "Bad Request".
@GET
@Path("{unique_id}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
开发者_如何学Gopublic Response getCompanyDetail(@PathParam("unique_id") long id, @QueryParam("view") final String view, @Context UriInfo ui) {
This is the log message:
2011-09-07 12:35:58,279 ERROR [STDERR] Sep 7, 2011 12:35:58 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java type, class com.dnb.applications.webservice.rest.view.response.GetCompanyDetailResponse, and MIME media type, application/xml, was not found
......
It works fine with JSON, though.
Here is the line that is blowing up:
return responseBuilder.entity(vo).build();
'vo' is our JAXB-annotated view object. It is annotated with @XmlType.
If we want to add XML support is this the right approach? I thought Jersey had an XML provider and handled XML by default.
Is there any issue with building the response for both JSON and XML in the same method?
The annotated class is missing the @XmlRootElement annotation. This works if returning JSON but not XML.
精彩评论