2009/4/1 Felipe Gaúcho <fgaucho_at_gmail.com>:
> @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
>
> I know the return type depends of some parameter in the request .. but
> which one ? how to choose between JSON and XML in runtime ?
>
> may I choose this through a browser url ? or I need to create a http
> request in other way ?
What I have done is to default to MediaType from http headers; gotten like:
@Get public Response myMethod (@Context HttpHeaders headers, ...)
{
MediaType type = headers.getMediaType();
}
which is what clients (including browser) send.
But also allow explicit override via query param for testing purposes
(since it's simpler to change than http headers browser sends).
And to use MediaType, need to use response builder, like:
return Response.ok(resultObject, type).build();
-+ Tatu +-