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:
Sebastien Deleuze
2019-04-30 16:05:09 +02:00
parent 2e6059f6b0
commit 89454e69c3
39 changed files with 144 additions and 147 deletions

View File

@@ -72,7 +72,6 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
@Test
public void canDecode() {
assertTrue(decoder.canDecode(forClass(Pojo.class), APPLICATION_JSON));
assertTrue(decoder.canDecode(forClass(Pojo.class), APPLICATION_JSON_UTF8));
assertTrue(decoder.canDecode(forClass(Pojo.class), APPLICATION_STREAM_JSON));
assertTrue(decoder.canDecode(forClass(Pojo.class), null));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,6 @@ import org.springframework.util.MimeTypeUtils;
import static java.util.Collections.singletonMap;
import static org.junit.Assert.*;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;
@@ -67,7 +66,6 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTestCase<Jackson2Js
public void canEncode() {
ResolvableType pojoType = ResolvableType.forClass(Pojo.class);
assertTrue(this.encoder.canEncode(pojoType, APPLICATION_JSON));
assertTrue(this.encoder.canEncode(pojoType, APPLICATION_JSON_UTF8));
assertTrue(this.encoder.canEncode(pojoType, APPLICATION_STREAM_JSON));
assertTrue(this.encoder.canEncode(pojoType, null));

View File

@@ -102,7 +102,7 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTestCas
bodyBuilder.part("name 2", "value 2+2");
bodyBuilder.part("logo", logo);
bodyBuilder.part("utf8", utf8);
bodyBuilder.part("json", new Foo("bar"), MediaType.APPLICATION_JSON_UTF8);
bodyBuilder.part("json", new Foo("bar"), MediaType.APPLICATION_JSON);
bodyBuilder.asyncPart("publisher", publisher, String.class);
Mono<MultiValueMap<String, HttpEntity<?>>> result = Mono.just(bodyBuilder.build());
@@ -144,7 +144,7 @@ public class MultipartHttpMessageWriterTests extends AbstractLeakCheckingTestCas
part = requestParts.getFirst("json");
assertEquals("json", part.name());
assertEquals(MediaType.APPLICATION_JSON_UTF8, part.headers().getContentType());
assertEquals(MediaType.APPLICATION_JSON, part.headers().getContentType());
String value = StringDecoder.textPlainOnly(false).decodeToMono(part.content(),
ResolvableType.forClass(String.class), MediaType.TEXT_PLAIN,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -139,7 +139,7 @@ public class MappingJackson2HttpMessageConverterTests {
assertTrue(result.contains("\"array\":[\"Foo\",\"Bar\"]"));
assertTrue(result.contains("\"bool\":true"));
assertTrue(result.contains("\"bytes\":\"AQI=\""));
assertEquals("Invalid content-type", new MediaType("application", "json", StandardCharsets.UTF_8),
assertEquals("Invalid content-type", MediaType.APPLICATION_JSON,
outputMessage.getHeaders().getContentType());
}
@@ -161,7 +161,7 @@ public class MappingJackson2HttpMessageConverterTests {
assertTrue(result.contains("\"array\":[\"Foo\",\"Bar\"]"));
assertTrue(result.contains("\"bool\":true"));
assertTrue(result.contains("\"bytes\":\"AQI=\""));
assertEquals("Invalid content-type", new MediaType("application", "json", StandardCharsets.UTF_8),
assertEquals("Invalid content-type", MediaType.APPLICATION_JSON,
outputMessage.getHeaders().getContentType());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -143,7 +143,7 @@ public class ProtobufHttpMessageConverterTests {
new ProtobufHttpMessageConverter.ProtobufJavaUtilSupport(null, null),
this.extensionRegistry);
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
MediaType contentType = MediaType.APPLICATION_JSON;
this.converter.write(this.testMsg, contentType, outputMessage);
assertEquals(contentType, outputMessage.getHeaders().getContentType());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.http.converter.smile;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
@@ -90,7 +89,7 @@ public class MappingJackson2SmileHttpMessageConverterTests {
body.setBytes(new byte[]{0x1, 0x2});
converter.write(body, null, outputMessage);
assertArrayEquals(mapper.writeValueAsBytes(body), outputMessage.getBodyAsBytes());
assertEquals("Invalid content-type", new MediaType("application", "x-jackson-smile", StandardCharsets.UTF_8),
assertEquals("Invalid content-type", new MediaType("application", "x-jackson-smile"),
outputMessage.getHeaders().getContentType());
}