users@jersey.java.net

RE: [Jersey] Set MediaType Programmatically

From: Jeremy Whitlock <jwhitlock_at_collab.net>
Date: Thu, 13 Nov 2008 10:38:08 -0800

> If you use Response.ResponseBuilder to create the response you can do
> something like this:
>
> @Path(/containers/list.{format})
> @Produces({"application/json", "application/xml"})
> public Response getAllContainers(@PathParam("format") String
format) {
> String type = format.equals("json") ? "application/json" :
> "application/xml";
> return Response.ok(getContainersFromEM()).type(type).build();
> }
>
> The "builder pattern" APIs (a method like type() that sets something
on
> the ResponseBuilder and returns a ResponseBuilder for continued
> customization) makes it really easy to configure your response exactly
> the way you would like it.

Awesome. This is what I was looking for.