title: Jersey - Set REST response encoding at runtime
body: <p>I am wondering if it's possible, using Jersey API, to set the response charset at runtime.</p>
  
  <p>If I set it like this:</p>
  
  <pre><code>public class MyRESTClass
  {
     private static final String encoding  = "UTF-8";
  
     @GET
     @Produces(MediaType.APPLICATION_JSON + ";charset=" + enconding)
     public String Call(@Context final HttpServletRequest servletReq, @QueryParam("somePar") String somePar)
     {
        ...
     }
  }
  </code></pre>
  
  <p>...it's OK</p>
  
  <p>But if I try and set it like this:</p>
  
  <pre><code>public class MyRESTClass
  {
     private static final String encoding  = getEncoding();
  
     public static final String getEncoding()
     {
        final String encoding = "UTF-8";
        return encoding;
     }
  
     @GET
     @Produces(MediaType.APPLICATION_JSON + ";charset=" + enconding)
     public String Call(@Context final HttpServletRequest servletReq, @QueryParam("somePar") String somePar)
     {
        ...
     }
  }
  </code></pre>
  
  <p>I get compile error:</p>
  
  <blockquote>
    <p>The value for annotation attribute Produces.value must be a constant
    expression</p>
  </blockquote>
  
  <p>I need this so I can set my application's REST encoding using a configuration file.</p>
  
  <p>Is there another way?</p>
  
  <p>Thanks</p>