Deprecate MediaType.APPLICATION_JSON_UTF8
This commit deprecates MediaType.APPLICATION_JSON_UTF8 and MediaType.APPLICATION_PROBLEM_JSON_UTF8 in favor of MediaType.APPLICATION_JSON and MediaType.APPLICATION_PROBLEM_JSON since UTF-8 encoding is now handled correctly by most browsers (related bug has been fixed in Chrome since September 2017). MediaType.APPLICATION_JSON is now used as the default JSON content type. Closes gh-22788
This commit is contained in:
@@ -350,7 +350,7 @@ mockMvc.get("/person/{name}", "Lee") {
|
||||
principal = Principal { "foo" }
|
||||
}.andExpect {
|
||||
status { isOk }
|
||||
content { contentType(APPLICATION_JSON_UTF8) }
|
||||
content { contentType(APPLICATION_JSON) }
|
||||
jsonPath("$.name") { value("Lee") }
|
||||
content { json("""{"someBoolean": false}""", false) }
|
||||
}.andDo {
|
||||
@@ -567,7 +567,7 @@ class UserHandler(builder: WebClient.Builder) {
|
||||
client.get().uri("...").awaitExchange().awaitBody<User>()))
|
||||
|
||||
suspend fun listApi(request: ServerRequest): ServerResponse =
|
||||
ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).bodyAndAwait(
|
||||
ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyAndAwait(
|
||||
client.get().uri("...").awaitExchange().awaitBody<User>())
|
||||
}
|
||||
----
|
||||
|
||||
@@ -141,10 +141,10 @@ Typically, you start by asserting the response status and headers, as follows:
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
client.get().uri("/persons/1")
|
||||
.accept(MediaType.APPLICATION_JSON_UTF8)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
.expectHeader().contentType(MediaType.APPLICATION_JSON)
|
||||
// ...
|
||||
----
|
||||
|
||||
|
||||
@@ -1342,7 +1342,7 @@ content types that a controller method produces, as the following example shows:
|
||||
[source,java,indent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@GetMapping(path = "/pets/{petId}", produces = "application/json;charset=UTF-8")
|
||||
@GetMapping(path = "/pets/{petId}", produces = "application/json")
|
||||
@ResponseBody
|
||||
public Pet getPet(@PathVariable String petId) {
|
||||
// ...
|
||||
@@ -1352,17 +1352,12 @@ content types that a controller method produces, as the following example shows:
|
||||
The media type can specify a character set. Negated expressions are supported -- for example,
|
||||
`!text/plain` means any content type other than `text/plain`.
|
||||
|
||||
NOTE: For JSON content type, you should specify the UTF-8 `charset` even if
|
||||
https://tools.ietf.org/html/rfc7159#section-11[RFC7159]
|
||||
clearly states that "`no charset parameter is defined for this registration,`" because some
|
||||
browsers require it to correctly interpret UTF-8 special characters.
|
||||
|
||||
You can declare a shared `produces` attribute at the class level. Unlike most other request
|
||||
mapping attributes, however, when used at the class level, a method-level `produces` attribute
|
||||
overrides rather than extend the class level declaration.
|
||||
|
||||
TIP: `MediaType` provides constants for commonly used media types -- e.g.
|
||||
`APPLICATION_JSON_UTF8_VALUE`, `APPLICATION_XML_VALUE`.
|
||||
`APPLICATION_JSON_VALUE`, `APPLICATION_XML_VALUE`.
|
||||
|
||||
|
||||
[[webflux-ann-requestmapping-params-and-headers]]
|
||||
|
||||
@@ -1504,7 +1504,7 @@ content types that a controller method produces, as the following example shows:
|
||||
[source,java,indent=0]
|
||||
[subs="verbatim,quotes"]
|
||||
----
|
||||
@GetMapping(path = "/pets/{petId}", produces = "application/json;charset=UTF-8") <1>
|
||||
@GetMapping(path = "/pets/{petId}", produces = "application/json") <1>
|
||||
@ResponseBody
|
||||
public Pet getPet(@PathVariable String petId) {
|
||||
// ...
|
||||
@@ -1515,17 +1515,12 @@ content types that a controller method produces, as the following example shows:
|
||||
The media type can specify a character set. Negated expressions are supported -- for example,
|
||||
`!text/plain` means any content type other than "text/plain".
|
||||
|
||||
NOTE: For the JSON content type, the UTF-8 charset should be specified even if
|
||||
https://tools.ietf.org/html/rfc7159#section-11[RFC7159]
|
||||
clearly states that "`no charset parameter is defined for this registration`", because some
|
||||
browsers require it to correctly interpret UTF-8 special characters.
|
||||
|
||||
You can declare a shared `produces` attribute at the class level. Unlike most other
|
||||
request-mapping attributes, however, when used at the class level, a method-level `produces` attribute
|
||||
overrides rather than extends the class-level declaration.
|
||||
|
||||
TIP: `MediaType` provides constants for commonly used media types, such as
|
||||
`APPLICATION_JSON_UTF8_VALUE` and `APPLICATION_XML_VALUE`.
|
||||
`APPLICATION_JSON_VALUE` and `APPLICATION_XML_VALUE`.
|
||||
|
||||
|
||||
[[mvc-ann-requestmapping-params-and-headers]]
|
||||
|
||||
Reference in New Issue
Block a user