How to set the charset with JAX-RS?

后端 未结 7 1097
时光说笑
时光说笑 2020-12-08 09:30

How can I set the charset with JAX-RS? I\'ve tried @Produces(\"text/html; charset=UTF-8\") but that was ignored and only text/html was send with th

相关标签:
7条回答
  • 2020-12-08 10:07

    Just to keep it up to date. Not sure whether this was supported in older versions of Jersey, but definitely if you decide to use ResponseBuilder.header(...) method you can use MediaType method withCharset(). Like this:

    return Response.status(Status.OK)
             .entity(result)
             .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_TYPE.withCharset("utf-8"))
             .build());
    
    0 讨论(0)
提交回复
热议问题