Document why "charset=UTF-8" is specified for JSON
Issue: SPR-14715
This commit is contained in:
@@ -96,11 +96,23 @@ public class MediaType extends MimeType implements Serializable {
|
||||
|
||||
/**
|
||||
* Public constant media type for {@code application/json;charset=UTF-8}.
|
||||
*
|
||||
* <p>This {@link MediaType#APPLICATION_JSON} variant should be used to set JSON
|
||||
* content type because while
|
||||
* <a href="https://tools.ietf.org/html/rfc7159#section-11">RFC7159</a>
|
||||
* clearly states that "no charset parameter is defined for this registration", some
|
||||
* browsers require it for interpreting correctly UTF-8 special characters.
|
||||
*/
|
||||
public static final MediaType APPLICATION_JSON_UTF8;
|
||||
|
||||
/**
|
||||
* A String equivalent of {@link MediaType#APPLICATION_JSON_UTF8}.
|
||||
*
|
||||
* <p>This {@link MediaType#APPLICATION_JSON_VALUE} variant should be used to set JSON
|
||||
* content type because while
|
||||
* <a href="https://tools.ietf.org/html/rfc7159#section-11">RFC7159</a>
|
||||
* clearly states that "no charset parameter is defined for this registration", some
|
||||
* browsers require it for interpreting correctly UTF-8 special characters.
|
||||
*/
|
||||
public static final String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
|
||||
|
||||
|
||||
@@ -193,10 +193,10 @@ public @interface RequestMapping {
|
||||
* <pre class="code">
|
||||
* produces = "text/plain"
|
||||
* produces = {"text/plain", "application/*"}
|
||||
* produces = "application/json; charset=UTF-8"
|
||||
* produces = MediaType.APPLICATION_JSON_UTF8_VALUE
|
||||
* </pre>
|
||||
* <p>It affects the actual content type written, for example to produce a JSON response
|
||||
* with UTF-8 encoding, {@code "application/json; charset=UTF-8"} should be used.
|
||||
* with UTF-8 encoding, {@link org.springframework.http.MediaType#APPLICATION_JSON_UTF8_VALUE} should be used.
|
||||
* <p>Expressions can be negated by using the "!" operator, as in "!text/plain", which matches
|
||||
* all requests with a {@code Accept} other than "text/plain".
|
||||
* <p><b>Supported at the type level as well as at the method level!</b>
|
||||
|
||||
Reference in New Issue
Block a user