Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.4
    • Fix Version/s: 2.3.8
    • Component/s: Plugin - JSON
    • Labels:
      None

      Description

      org.apache.struts2.json.JSONResult uses the configured default encoding (in the struts properties, with the "struts.i18n.encoding" key) when setting the charset part in the response's content type.

      Shouldn't JSONResult.getEncoding() always return UTF-8, similar to the resolution of WW-3059?

      A simple workaround is to override JSONResult.getEncoding() and let it return UTF-8 but it would be preferrable if this was included in the distribution.

        Activity

        Hide
        Lukasz Lenart added a comment -

        What's wrong with setting up struts.i18n.encoding ?

        Show
        Lukasz Lenart added a comment - What's wrong with setting up struts.i18n.encoding ?
        Hide
        Anders Lundberg added a comment -

        Same reason as not using struts.i18n.encoding in WW-3059. A struts application supports any encoding, thanks to struts.i18n.encoding, but a json string, submitted and received by XMLHttpRequest, has to be UTF-8 encoded.

        Show
        Anders Lundberg added a comment - Same reason as not using struts.i18n.encoding in WW-3059 . A struts application supports any encoding, thanks to struts.i18n.encoding, but a json string, submitted and received by XMLHttpRequest, has to be UTF-8 encoded.
        Hide
        Lukasz Lenart added a comment -

        Is it somehow specified? That JSON should always be encoded as UTF8? Or it's just an assumption because is used throughout XMLHttpRequest?

        Show
        Lukasz Lenart added a comment - Is it somehow specified? That JSON should always be encoded as UTF8? Or it's just an assumption because is used throughout XMLHttpRequest?
        Hide
        Lukasz Lenart added a comment -

        What about adding a new param - encoding which can be defined per result, by default set to UTF-8 ?

        <result-types>
            <result-type name="json" class="org.apache.struts2.json.JSONResult">
                <param name="encoding">UTF-8</param>
            </result-type>
        </result-types>
        
        Show
        Lukasz Lenart added a comment - What about adding a new param - encoding which can be defined per result, by default set to UTF-8 ? <result-types> <result-type name= "json" class= "org.apache.struts2.json.JSONResult" > <param name= "encoding" > UTF-8 </param> </result-type> </result-types>
        Hide
        Anders Lundberg added a comment -

        That's a nice solution. And if I revert my initial suggestion, keeping the default value as before, i.e. taken from the struts.i18n.encoding setting, should make this change backward compatible.

        Show
        Anders Lundberg added a comment - That's a nice solution. And if I revert my initial suggestion, keeping the default value as before, i.e. taken from the struts.i18n.encoding setting, should make this change backward compatible.
        Hide
        Lukasz Lenart added a comment -

        Yes, by default the param will be null and if not set, struts.i18n.encoding will be used instead. But I think with 3.x version we can change the default behaviour to be by default set to UTF-8

        Show
        Lukasz Lenart added a comment - Yes, by default the param will be null and if not set, struts.i18n.encoding will be used instead. But I think with 3.x version we can change the default behaviour to be by default set to UTF-8
        Hide
        Lukasz Lenart added a comment -

        Solved, thanks for reporting.

        Show
        Lukasz Lenart added a comment - Solved, thanks for reporting.
        Hide
        Hudson added a comment -

        Integrated in Struts2-JDK5 #21 (See https://builds.apache.org/job/Struts2-JDK5/21/)
        WW-3863 Allows to define encoding per result (Revision 1421740)

        Result = FAILURE
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
        • /struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java
        Show
        Hudson added a comment - Integrated in Struts2-JDK5 #21 (See https://builds.apache.org/job/Struts2-JDK5/21/ ) WW-3863 Allows to define encoding per result (Revision 1421740) Result = FAILURE lukaszlenart : Files : /struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java /struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONResultTest.java

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Anders Lundberg
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development