Skip to content

Spring default characterEncoding #26171

@vojkny

Description

@vojkny

Since Spring 5.2 MediaType.APPLICATION_JSON_UTF8 is @deprecated as described within MediaType class:

/**
 * A String equivalent of \{@link MediaType#APPLICATION_JSON_UTF8}.
 * @deprecated as of 5.2 in favor of \{@link #APPLICATION_JSON_VALUE}
 * since major browsers like Chrome
 * <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=438464">
 * now comply with the specification</a> and interpret correctly UTF-8 special
 * characters without requiring a \{@code charset=UTF-8} parameter.
 */
@Deprecated
public static final String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";

So basically everyone should be using MediaType.APPLICATION_JSON_VALUE without (UTF8 information) instead. This is unfortunately in conflict with MockHttpServletResponse:

private String characterEncoding = "ISO-8859-1";

So even thought UTF8 is expected by default, the testing environment is in violation with aboves:

now comply with the specification</a> and interpret correctly UTF-8 special

The tests which explicitly don't override this encoding will fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions