users@jersey.java.net

Re: [Jersey] how to set the response encoding ?

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Sat, 29 Aug 2009 10:25:09 -0700

Felipe Gaścho wrote:
> How to set the response encoding of my Jersey resources ?
>
> * or other response HTTP headers ?
>
>
Have your resource method return a "javax.ws.rs.core.Resonse" instead of
an entity object class directly. You can use its "builder pattern" APIs
to add as many headers as you like:

    @GET
    public Response get(...) {
        Object entity = ...; // The object you would normally have been
returning
        return Response.ok(entity).
            header("Content-Language", "en-us").
            build();
    }

There are also shortcut methds for many of the common HTTP headers, as
well as a way to set status codes other than 200.

Craig