Reputation: 7011
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})
public 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?
Upvotes: 2
Views: 859
Reputation: 7011
The annotated class is missing the @XmlRootElement annotation. This works if returning JSON but not XML.
Upvotes: 4