File tree Expand file tree Collapse file tree 4 files changed +34
-6
lines changed
spring-web/src/main/java/org/springframework Expand file tree Collapse file tree 4 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -96,11 +96,23 @@ public class MediaType extends MimeType implements Serializable {
96
96
97
97
/**
98
98
* Public constant media type for {@code application/json;charset=UTF-8}.
99
+ *
100
+ * <p>This {@link MediaType#APPLICATION_JSON} variant should be used to set JSON
101
+ * content type because while
102
+ * <a href="https://tools.ietf.org/html/rfc7159#section-11">RFC7159</a>
103
+ * clearly states that "no charset parameter is defined for this registration", some
104
+ * browsers require it for interpreting correctly UTF-8 special characters.
99
105
*/
100
106
public static final MediaType APPLICATION_JSON_UTF8 ;
101
107
102
108
/**
103
109
* A String equivalent of {@link MediaType#APPLICATION_JSON_UTF8}.
110
+ *
111
+ * <p>This {@link MediaType#APPLICATION_JSON_VALUE} variant should be used to set JSON
112
+ * content type because while
113
+ * <a href="https://tools.ietf.org/html/rfc7159#section-11">RFC7159</a>
114
+ * clearly states that "no charset parameter is defined for this registration", some
115
+ * browsers require it for interpreting correctly UTF-8 special characters.
104
116
*/
105
117
public static final String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8" ;
106
118
Original file line number Diff line number Diff line change 193
193
* <pre class="code">
194
194
* produces = "text/plain"
195
195
* produces = {"text/plain", "application/*"}
196
- * produces = "application/json; charset=UTF-8"
196
+ * produces = MediaType.APPLICATION_JSON_UTF8_VALUE
197
197
* </pre>
198
198
* <p>It affects the actual content type written, for example to produce a JSON response
199
- * with UTF-8 encoding, {@code "application/json; charset=UTF-8" } should be used.
199
+ * with UTF-8 encoding, {@link org.springframework.http.MediaType#APPLICATION_JSON_UTF8_VALUE } should be used.
200
200
* <p>Expressions can be negated by using the "!" operator, as in "!text/plain", which matches
201
201
* all requests with a {@code Accept} other than "text/plain".
202
202
* <p><b>Supported at the type level as well as at the method level!</b>
Original file line number Diff line number Diff line change @@ -1192,7 +1192,7 @@ overrides rather than extend the class level declaration.
1192
1192
[TIP]
1193
1193
====
1194
1194
`MediaType` provides constants for commonly used media types -- e.g.
1195
- `APPLICATION_JSON_VALUE`, `APPLICATION_JSON_UTF8_VALUE `.
1195
+ `APPLICATION_JSON_VALUE`, `APPLICATION_XML_VALUE `.
1196
1196
====
1197
1197
1198
1198
@@ -1216,14 +1216,22 @@ content types that a controller method produces:
1216
1216
The media type can specify a character set. Negated expressions are supported -- e.g.
1217
1217
`!text/plain` means any content type other than "text/plain".
1218
1218
1219
+ [NOTE]
1220
+ ====
1221
+ For JSON content type, the UTF-8 charset should be specified even if
1222
+ https://tools.ietf.org/html/rfc7159#section-11[RFC7159]
1223
+ clearly states that "no charset parameter is defined for this registration" because some
1224
+ browsers require it for interpreting correctly UTF-8 special characters.
1225
+ ====
1226
+
1219
1227
You can declare a shared produces attribute at the class level. Unlike most other request
1220
1228
mapping attributes however when used at the class level, a method-level produces attribute
1221
1229
overrides rather than extend the class level declaration.
1222
1230
1223
1231
[TIP]
1224
1232
====
1225
1233
`MediaType` provides constants for commonly used media types -- e.g.
1226
- `APPLICATION_JSON_VALUE `, `APPLICATION_JSON_UTF8_VALUE `.
1234
+ `APPLICATION_JSON_UTF8_VALUE `, `APPLICATION_XML_VALUE `.
1227
1235
====
1228
1236
1229
1237
Original file line number Diff line number Diff line change @@ -1425,7 +1425,7 @@ will overrides rather than extend the class level declaration.
1425
1425
[TIP]
1426
1426
====
1427
1427
`MediaType` provides constants for commonly used media types -- e.g.
1428
- `APPLICATION_JSON_VALUE`, `APPLICATION_JSON_UTF8_VALUE `.
1428
+ `APPLICATION_JSON_VALUE`, `APPLICATION_XML_VALUE `.
1429
1429
====
1430
1430
1431
1431
@@ -1449,14 +1449,22 @@ content types that a controller method produces:
1449
1449
The media type can specify a character set. Negated expressions are supported -- e.g.
1450
1450
`!text/plain` means any content type other than "text/plain".
1451
1451
1452
+ [NOTE]
1453
+ ====
1454
+ For JSON content type, the UTF-8 charset should be specified even if
1455
+ https://tools.ietf.org/html/rfc7159#section-11[RFC7159]
1456
+ clearly states that "no charset parameter is defined for this registration" because some
1457
+ browsers require it for interpreting correctly UTF-8 special characters.
1458
+ ====
1459
+
1452
1460
You can declare a shared produces attribute at the class level. Unlike most other request
1453
1461
mapping attributes however when used at the class level, a method-level produces attribute
1454
1462
will overrides rather than extend the class level declaration.
1455
1463
1456
1464
[TIP]
1457
1465
====
1458
1466
`MediaType` provides constants for commonly used media types -- e.g.
1459
- `APPLICATION_JSON_VALUE `, `APPLICATION_JSON_UTF8_VALUE `.
1467
+ `APPLICATION_JSON_UTF8_VALUE `, `APPLICATION_XML_VALUE `.
1460
1468
====
1461
1469
1462
1470
You can’t perform that action at this time.
0 commit comments