Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-16491

(7.2.z) RESTEASY-2171 - JsonBindingProvider use incorrect charset encoding

XMLWordPrintable

      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


      Checking this issue with Wireshark and this end-point:

          @GET
          @Produces("application/json")
          @Path("a")
          public CustomObject a() throws Exception {
              return new CustomObject().setA("öü");
          }
      
      • default encoding (UTF8) + default json provider (JSON-B)
        • correct: UTF8 - "öü" - 22 c3 b6 c3 bc 22
      • default encoding (UTF8) + old json provider (Jackson)
        • correct: UTF8 - "öü" - 22 c3 b6 c3 bc 22
      • us-ascii + default json provider (JSON-B)
      • us-ascii + old json provider (Jackson)
        • correct: UTF8 - "öü" - 22 c3 b6 c3 bc 22

      Upstream jira: https://issues.jboss.org/browse/RESTEASY-2171

              rhn-support-iweiss Ingo Weiss
              mkopecky@redhat.com Marek Kopecky
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: