Skip to content

@ResponseBody doesn't obey CharacterEncodingFilter [SPR-6443] #11109

@spring-projects-issues

Description

@spring-projects-issues

Morten Egelund Rasmussen opened SPR-6443 and commented

I have a @Controller class defined as a REST webservice endpoint. It has a method, which is annotated with @ResponseBody.

Class looks something like this:

@Controller
@RequestMapping("/foo")
public class Foo {
    @RequestMapping(value="/foobar", method=RequestMethod.GET)
    @ResponseBody
    public string getFoobar() {
      // Do something that returns some UTF-8 stuff (probably some XML).
    }
}

It seems that it always returns content encoded in ISO-8859-1, even if I have a CharacterEncodingFilter defined first in the chain like:

    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <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-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

I have debugged and printed the string output to the logs, and it goes to the logfile just fine in UTF-8. However, it ends out in the browser as ISO-8859-1.


Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions