Hi All,
While working on my example for serializing collections to JSON
and XML, I ran into a problem. (Using JAXB support built into jersey
and jersey-json of course.) Basically, I wanted to have one method
return two different content types. It was suggested yesterday to use
the ResponseBuilder and return a Response object instead of the actual
entity object(s). It has worked fine until now. Basically, I have the
following:
@GET
@Path("people.{format}")
public List<Person> getPeople(@PathParam("format") String format) {
// return Response.ok(people).type(formats.get(format)).build();
return people;
}
With the current approach, I only get JSON serialization since there is
no way to tell Jersey that I want to change the return format. If I
update the method to return a Response instead of the List<Person>, JAXB
tells me that there is no content writer for java.util.ArrayList. It
appears that when returning a JAXB-formatted response, your methods
cannot return a Response object and must return the entity, or list of
entities. If that is the case, then the suggestion to use a
ResponseBuilder is flawed and I need a working way to tell the response
what format to use without using Response objects. If that is not the
case, what am I doing wrong or what have I uncovered?
Take care,
Jeremy Whitlock | Software Engineer | CollabNet, Inc.
8000 Marina Blvd. Suite 600 | Brisbane, CA 94005 | USA
O 650.228.2516 | C 970.988.8822 | jwhitlock_at_collab.net