From 5044b70a4038f2ae29cee262f63fb0e940297bda Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Sun, 8 Dec 2024 21:01:11 +0100 Subject: [PATCH] Remove deprecated MediaType entries See gh-33809 --- .../org/springframework/http/MediaType.java | 73 ------------------- .../http/codec/json/Jackson2JsonEncoder.java | 5 +- .../codec/json/Jackson2JsonDecoderTests.java | 3 - .../codec/json/Jackson2JsonEncoderTests.java | 6 +- .../annotation/ReactiveTypeHandler.java | 4 - .../annotation/ReactiveTypeHandlerTests.java | 13 ---- 6 files changed, 4 insertions(+), 100 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 77e116d7902..e37d4ffdb97 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -18,7 +18,6 @@ package org.springframework.http; 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; @@ -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 - * - * now comply with the specification 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 - * - * now comply with the specification 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}. */ @@ -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 - * Problem Details for HTTP APIs, 6.1. application/problem+json - * @deprecated as of 5.2 in favor of {@link #APPLICATION_PROBLEM_JSON} - * since major browsers like Chrome - * - * now comply with the specification 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 - * - * now comply with the specification 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 @@ -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}. */ @@ -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"); diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java index 2a79854b3d8..43643fa5bf4 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java @@ -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. @@ -59,10 +59,9 @@ public class Jackson2JsonEncoder extends AbstractJackson2Encoder { 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(); } diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java index ea1406dea52..8fa0a67b52f 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java @@ -53,7 +53,6 @@ import static org.assertj.core.api.Assertions.assertThat; 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; @@ -77,11 +76,9 @@ class Jackson2JsonDecoderTests extends AbstractDecoderTests @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(); diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java index 851b4406b90..e53d634e941 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonEncoderTests.java @@ -49,11 +49,11 @@ 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_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 { @@ -64,12 +64,10 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests @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), @@ -94,7 +92,7 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests 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")) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java index 5e3e589b8b9..59b6db526e3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java @@ -201,7 +201,6 @@ class ReactiveTypeHandler { * @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 acceptedMediaTypes) { for (MediaType acceptedType : acceptedMediaTypes) { @@ -220,9 +219,6 @@ class ReactiveTypeHandler { 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 } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java index e59af479919..6d062b44d47 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java @@ -158,19 +158,6 @@ class ReactiveTypeHandlerTests { .isEqualTo(MediaType.APPLICATION_NDJSON); } - @SuppressWarnings("deprecation") - @Test - void findsConcreteStreamingMediaType_plainStreamingJsonFirst() { - final List 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 {