Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-2418

Wrong encoding content in JSON response

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Complete
    • Affects Version/s: 1.1.3.RELEASE
    • Fix Version/s: 1.1.4.RELEASE
    • Component/s: WEB MVC
    • Labels:
      None
    • Environment:
      Ubuntu 10.04 LTS x86_64
      system encoding: UTF-8
      PostgreSQL DB encoding UTF-8

      Description

      I have a controller like this:

      TcmnNucleosController.java
      @RooWebScaffold(path = "tcmnnucleoses", formBackingObject = TcmnNucleos.class, create = false, update = false, delete = false, exposeJson=true)
      @RequestMapping("/tcmnnucleoses")
      @Controller
      public class TcmnNucleosController {
      
          @RequestMapping(params = "find=ByProvincia", method = RequestMethod.GET) //, headers = "Accept=application/json")
          @ResponseBody
          public String jsonFindTcmnNucleosesByProvincia(
                  @RequestParam("provincia") String provincia) {
       
              return TcmnNucleos.toJsonArray(TcmnNucleos
                      .findTcmnNucleosesByProvincia(
                              TcmnProvincias.findTcmnProvincias(provincia))
                      .getResultList());
          }
      
      

      In 'TcmnNucleos' postgreSQL table, enconded in UTF-8, contains data like:

      "Pruébañ"
      "Quart"
      "Mislata"
      "Manresa"
      
      

      This call returns this:

      $ wget -O - -S --header='Accept: application/json,application/javascript' 'http://localhost:8080/acuses/tcmnnucleoses/?provincia=1&find=ByProvincia'
      --2011-05-11 15:50:15--  http://localhost:8080/acuses/tcmnnucleoses/?provincia=1&find=ByProvincia
      Resolviendo localhost... ::1, 127.0.0.1
      Conectando a localhost|::1|:8080... conectado.
      Petición HTTP enviada, esperando respuesta... 
        HTTP/1.1 200 OK
        Server: Apache-Coyote/1.1
        Content-Type: application/json;charset=UTF-8
        Content-Length: 1854
        Date: Wed, 11 May 2011 13:50:16 GMT
        Connection: keep-alive
      Longitud: 1854 (1,8K) [application/json]
      Guardando en: «STDOUT»
      [{...:"Pru�ba�","dnuclc":null,...}]
      

      JSON returned content is encoded in WINDOWS-1252 but http header says application/json;charset=UTF-8

      Web.xml has no changes.

      web.xml
        <filter>
              <filter-name>CharacterEncodingFilter</filter-name>
              <filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter</filter-class&gt;
              <init-param>
                  <param-name>encoding</param-name>
                  <param-value>UTF-8</param-value>
              </init-param>
              <init-param>
                  <param-name>forceEncoding</param-name>
                  <param-value>true</param-value>
              </init-param>
          </filter>
          
          
          
          <filter>
              <filter-name>HttpMethodFilter</filter-name>
              <filter-class&gt;org.springframework.web.filter.HiddenHttpMethodFilter</filter-class&gt;
          </filter>
          ....
          ....
      
         <filter-mapping>
              <filter-name>CharacterEncodingFilter</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
          
          ....
          ....
      
      

        Attachments

          Activity

            People

            Assignee:
            sschmidt Stefan Schmidt
            Reporter:
            jmvivo Jose Manuel Vivó ( Chema ) - DISID.
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: