If you want to do this in a neutral implementation mode of JAX-RS, you can reset the Content-Type in MessageBodyWriter. Something like:
public void writeTo(Object obj, Class<?> cls, Type type, Annotation[] annotations, MediaType mt, MultivaluedMap<String, Object> responseHttpHeaders, OutputStream stream) throws IOException { responseHttpHeaders.putSingle(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE, mt.toString() + ";charset=UTF-8"); }
If you have different character sets besides UTF-8 for each resource method, you can create a custom annotation and add it to each resource method. Then try using the annotation parameter in the writeTo () method.
Just FYI, Apache Wink supports the use of encoding and other attributes for media types. Hopefully future JAX-RS spec specifications will facilitate this.
Bryant Luk Aug 09 '10 at 10:01 2010-08-09 22:01
source share