-
Bug
-
Resolution: Done
-
Blocker
-
3.6.2.Final
-
-
Compatibility/Configuration, User Experience
-
Workaround Exists
-
With a rest resource method returning a POJO and annotated with @Produces(Mediatype.APPLICATION_JSON), the returned response response is incorrectly encoded (uses US_ASCII instead of utf-8).
The workaround is to add a parameter to the mediatype: @Produces("application/json;charset=utf-8").
There is 2 issues concerning compliance with the RFC7159 json spec:
- As per the json spec, charset parameters should be discarded:
Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.
- As per the json spec, json is utf-8 encoded:
JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32. The default encoding is UTF-8, and JSON texts that are encoded in UTF-8 are interoperable in the sense that they will be read successfully by the maximum number of implementations
The source of these issues lies in org.jboss.resteasy.plugins.providers.jsonb.AbstractJsonBindingProvider#getCharset, which attempts to figure out the charset to use, defaulting to Charset.defaultCharset(), whereas utf-8 should be used and this logic is not required:
public static Charset getCharset(final MediaType mediaType) { if (mediaType != null) { String charset = mediaType.getParameters().get("charset"); if (charset != null) return Charset.forName(charset); } return Charset.defaultCharset(); }
This method is called from org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider#writeTo:
entityStream.write(jsonb.toJson(t).getBytes(getCharset(mediaType)));
- is cloned by
-
JBEAP-16491 (7.2.z) RESTEASY-2171 - JsonBindingProvider use incorrect charset encoding
- Closed
-
JBEAP-16540 (CD16) JsonBindingProvider use incorrect charset encoding
- Closed