Skip to content

Commit

Permalink
Remove deprecated MediaType entries
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Dec 8, 2024
1 parent ff28d2d commit 5044b70
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 100 deletions.
73 changes: 0 additions & 73 deletions spring-web/src/main/java/org/springframework/http/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -120,32 +119,9 @@ public class MediaType extends MimeType implements Serializable {

/**
* A String equivalent of {@link MediaType#APPLICATION_JSON}.
* @see #APPLICATION_JSON_UTF8_VALUE
*/
public static final String APPLICATION_JSON_VALUE = "application/json";

/**
* Media type for {@code application/json;charset=UTF-8}.
* @deprecated as of 5.2 in favor of {@link #APPLICATION_JSON}
* 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 MediaType APPLICATION_JSON_UTF8;

/**
* 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";

/**
* Media type for {@code application/octet-stream}.
*/
Expand Down Expand Up @@ -182,32 +158,6 @@ public class MediaType extends MimeType implements Serializable {
*/
public static final String APPLICATION_PROBLEM_JSON_VALUE = "application/problem+json";

/**
* Media type for {@code application/problem+json}.
* @since 5.0
* @see <a href="https://www.iana.org/assignments/media-types/application/problem+json">
* Problem Details for HTTP APIs, 6.1. application/problem+json</a>
* @deprecated as of 5.2 in favor of {@link #APPLICATION_PROBLEM_JSON}
* 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 MediaType APPLICATION_PROBLEM_JSON_UTF8;

/**
* A String equivalent of {@link MediaType#APPLICATION_PROBLEM_JSON_UTF8}.
* @since 5.0
* @deprecated as of 5.2 in favor of {@link #APPLICATION_PROBLEM_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_PROBLEM_JSON_UTF8_VALUE = "application/problem+json;charset=UTF-8";

/**
* Media type for {@code application/problem+xml}.
* @since 5.0
Expand Down Expand Up @@ -258,26 +208,6 @@ public class MediaType extends MimeType implements Serializable {
*/
public static final String APPLICATION_NDJSON_VALUE = "application/x-ndjson";

/**
* Media type for {@code application/stream+json}.
* @since 5.0
* @deprecated as of 5.3, see notice on {@link #APPLICATION_STREAM_JSON_VALUE}.
*/
@Deprecated
public static final MediaType APPLICATION_STREAM_JSON;

/**
* A String equivalent of {@link MediaType#APPLICATION_STREAM_JSON}.
* @since 5.0
* @deprecated as of 5.3 since it originates from the W3C Activity Streams
* specification which has a more specific purpose and has been since
* replaced with a different mime type. Use {@link #APPLICATION_NDJSON} as
* a replacement or any other line-delimited JSON format (for example, JSON Lines,
* JSON Text Sequences).
*/
@Deprecated
public static final String APPLICATION_STREAM_JSON_VALUE = "application/stream+json";

/**
* Media type for {@code application/xhtml+xml}.
*/
Expand Down Expand Up @@ -440,16 +370,13 @@ public class MediaType extends MimeType implements Serializable {
APPLICATION_FORM_URLENCODED = new MediaType("application", "x-www-form-urlencoded");
APPLICATION_GRAPHQL_RESPONSE = new MediaType("application", "graphql-response+json");
APPLICATION_JSON = new MediaType("application", "json");
APPLICATION_JSON_UTF8 = new MediaType("application", "json", StandardCharsets.UTF_8);
APPLICATION_NDJSON = new MediaType("application", "x-ndjson");
APPLICATION_OCTET_STREAM = new MediaType("application", "octet-stream");
APPLICATION_PDF = new MediaType("application", "pdf");
APPLICATION_PROBLEM_JSON = new MediaType("application", "problem+json");
APPLICATION_PROBLEM_JSON_UTF8 = new MediaType("application", "problem+json", StandardCharsets.UTF_8);
APPLICATION_PROBLEM_XML = new MediaType("application", "problem+xml");
APPLICATION_PROTOBUF = new MediaType("application", "x-protobuf");
APPLICATION_RSS_XML = new MediaType("application", "rss+xml");
APPLICATION_STREAM_JSON = new MediaType("application", "stream+json");
APPLICATION_XHTML_XML = new MediaType("application", "xhtml+xml");
APPLICATION_XML = new MediaType("application", "xml");
APPLICATION_YAML = new MediaType("application", "yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -59,10 +59,9 @@ public Jackson2JsonEncoder() {
this(Jackson2ObjectMapperBuilder.json().build());
}

@SuppressWarnings("deprecation")
public Jackson2JsonEncoder(ObjectMapper mapper, MimeType... mimeTypes) {
super(mapper, mimeTypes);
setStreamingMediaTypes(Arrays.asList(MediaType.APPLICATION_NDJSON, MediaType.APPLICATION_STREAM_JSON));
setStreamingMediaTypes(Arrays.asList(MediaType.APPLICATION_NDJSON));
this.ssePrettyPrinter = initSsePrettyPrinter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_NDJSON;
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;

Expand All @@ -77,11 +76,9 @@ public Jackson2JsonDecoderTests() {

@Override
@Test
@SuppressWarnings("deprecation")
public void canDecode() {
assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), APPLICATION_JSON)).isTrue();
assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), APPLICATION_NDJSON)).isTrue();
assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), APPLICATION_STREAM_JSON)).isTrue();
assertThat(decoder.canDecode(ResolvableType.forClass(Pojo.class), null)).isTrue();

assertThat(decoder.canDecode(ResolvableType.forClass(String.class), null)).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_NDJSON;
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;
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;

/**
* Tests for {@link Jackson2JsonEncoder}.
* @author Sebastien Deleuze
*/
class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder> {
Expand All @@ -64,12 +64,10 @@ public Jackson2JsonEncoderTests() {

@Override
@Test
@SuppressWarnings("deprecation")
public void canEncode() {
ResolvableType pojoType = ResolvableType.forClass(Pojo.class);
assertThat(this.encoder.canEncode(pojoType, APPLICATION_JSON)).isTrue();
assertThat(this.encoder.canEncode(pojoType, APPLICATION_NDJSON)).isTrue();
assertThat(this.encoder.canEncode(pojoType, APPLICATION_STREAM_JSON)).isTrue();
assertThat(this.encoder.canEncode(pojoType, null)).isTrue();

assertThat(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
Expand All @@ -94,7 +92,7 @@ public void encode() throws Exception {
new Pojo("foofoo", "barbar"),
new Pojo("foofoofoo", "barbarbar"));

testEncodeAll(input, ResolvableType.forClass(Pojo.class), APPLICATION_STREAM_JSON, null, step -> step
testEncodeAll(input, ResolvableType.forClass(Pojo.class), APPLICATION_NDJSON, null, step -> step
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n"))
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n"))
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public ResponseBodyEmitter handleValue(Object returnValue, MethodParameter retur
* @return the concrete streaming {@code MediaType} if one could be found or {@code null}
* if none could be found
*/
@SuppressWarnings("deprecation")
@Nullable
static MediaType findConcreteJsonStreamMediaType(Collection<MediaType> acceptedMediaTypes) {
for (MediaType acceptedType : acceptedMediaTypes) {
Expand All @@ -220,9 +219,6 @@ static MediaType findConcreteJsonStreamMediaType(Collection<MediaType> acceptedM
else if (MediaType.APPLICATION_NDJSON.includes(acceptedType)) {
return MediaType.APPLICATION_NDJSON;
}
else if (MediaType.APPLICATION_STREAM_JSON.includes(acceptedType)) {
return MediaType.APPLICATION_STREAM_JSON;
}
}
return null; // not a concrete streaming type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,6 @@ void findsConcreteStreamingMediaType_plainNdJsonFirst() {
.isEqualTo(MediaType.APPLICATION_NDJSON);
}

@SuppressWarnings("deprecation")
@Test
void findsConcreteStreamingMediaType_plainStreamingJsonFirst() {
final List<MediaType> accept = List.of(
MediaType.ALL,
MediaType.APPLICATION_STREAM_JSON,
MediaType.parseMediaType("application/*+x-ndjson"),
MediaType.parseMediaType("application/vnd.myapp.v1+x-ndjson"));

assertThat(ReactiveTypeHandler.findConcreteJsonStreamMediaType(accept))
.isEqualTo(MediaType.APPLICATION_STREAM_JSON);
}

@Test
void deferredResultSubscriberWithOneValue() throws Exception {

Expand Down

0 comments on commit 5044b70

Please sign in to comment.