Deprecate for removal Jackson 2 support

This commit deprecate for removal (likely in a future 7.x release) the
Jackson 2 support in favor of the Jackson 3 one.

Closes gh-33798
This commit is contained in:
Sébastien Deleuze
2025-05-13 16:37:54 +02:00
parent 6ae89ea397
commit 2a29e16456
60 changed files with 141 additions and 7 deletions

View File

@@ -43,6 +43,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
* @see AbstractJackson2Encoder
*/
@BenchmarkMode(Mode.Throughput)
@SuppressWarnings("removal")
public class Jackson2JsonEncoderBenchmark {

View File

@@ -111,6 +111,7 @@ public abstract class AbstractJacksonEncoder extends JacksonCodecSupport impleme
}
@Override
@SuppressWarnings("removal")
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
if (!supportsMimeType(mimeType)) {
return false;

View File

@@ -40,7 +40,10 @@ import org.springframework.util.MimeType;
* @since 5.2
* @see Jackson2CborEncoder
* @see <a href="https://github.com/spring-projects/spring-framework/issues/20513">Add CBOR support to WebFlux</a>
* @deprecated since 7.0 in favor of {@link JacksonCborDecoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2CborDecoder extends AbstractJackson2Decoder {
public Jackson2CborDecoder() {

View File

@@ -41,7 +41,10 @@ import org.springframework.util.MimeType;
* @since 5.2
* @see Jackson2CborDecoder
* @see <a href="https://github.com/spring-projects/spring-framework/issues/20513">Add CBOR support to WebFlux</a>
* @deprecated since 7.0 in favor of {@link JacksonCborEncoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2CborEncoder extends AbstractJackson2Encoder {
public Jackson2CborEncoder() {

View File

@@ -47,6 +47,7 @@ import org.springframework.core.io.buffer.DataBufferLimitException;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.PooledDataBuffer;
import org.springframework.core.log.LogFormatUtils;
import org.springframework.http.codec.AbstractJacksonDecoder;
import org.springframework.http.codec.HttpMessageDecoder;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
@@ -61,7 +62,10 @@ import org.springframework.util.MimeType;
* @author Arjen Poutsma
* @since 5.0
* @see <a href="https://github.com/FasterXML/jackson-core/issues/57" target="_blank">Add support for non-blocking ("async") JSON parsing</a>
* @deprecated since 7.0 in favor of {@link AbstractJacksonDecoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport implements HttpMessageDecoder<Object> {
private int maxInMemorySize = 256 * 1024;

View File

@@ -50,6 +50,7 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.log.LogFormatUtils;
import org.springframework.http.MediaType;
import org.springframework.http.codec.AbstractJacksonEncoder;
import org.springframework.http.codec.HttpMessageEncoder;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -66,7 +67,10 @@ import org.springframework.util.MimeType;
* @author Sebastien Deleuze
* @author Arjen Poutsma
* @since 5.0
* @deprecated since 7.0 in favor of {@link AbstractJacksonEncoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport implements HttpMessageEncoder<Object> {
private static final byte[] NEWLINE_SEPARATOR = {'\n'};

View File

@@ -40,6 +40,7 @@ import org.springframework.core.codec.Hints;
import org.springframework.http.HttpLogging;
import org.springframework.http.MediaType;
import org.springframework.http.ProblemDetail;
import org.springframework.http.codec.JacksonCodecSupport;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.Assert;
@@ -53,7 +54,9 @@ import org.springframework.util.ObjectUtils;
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @since 5.0
* @deprecated since 7.0 in favor of {@link JacksonCodecSupport}
*/
@Deprecated(since = "7.0", forRemoval = true)
public abstract class Jackson2CodecSupport {
/**

View File

@@ -31,6 +31,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.codec.CharBufferDecoder;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.codec.AbstractJacksonDecoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -43,7 +44,10 @@ import org.springframework.util.MimeTypeUtils;
* @author Rossen Stoyanchev
* @since 5.0
* @see Jackson2JsonEncoder
* @deprecated since 7.0 in favor of {@link AbstractJacksonDecoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2JsonDecoder extends AbstractJackson2Decoder {
private static final CharBufferDecoder CHAR_BUFFER_DECODER = CharBufferDecoder.textPlainOnly(Arrays.asList(",", "\n"), false);

View File

@@ -44,7 +44,10 @@ import org.springframework.util.MimeType;
* @author Arjen Poutsma
* @since 5.0
* @see Jackson2JsonDecoder
* @deprecated since 7.0 in favor of {@link JacksonJsonEncoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2JsonEncoder extends AbstractJackson2Encoder {
private static final List<MimeType> problemDetailMimeTypes =

View File

@@ -19,6 +19,7 @@ package org.springframework.http.codec.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import org.springframework.http.codec.smile.JacksonSmileDecoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
@@ -31,7 +32,10 @@ import org.springframework.util.MimeType;
* @author Rossen Stoyanchev
* @since 5.0
* @see Jackson2JsonEncoder
* @deprecated since 7.0 in favor of {@link JacksonSmileDecoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2SmileDecoder extends AbstractJackson2Decoder {
private static final MimeType[] DEFAULT_SMILE_MIME_TYPES = new MimeType[] {

View File

@@ -25,6 +25,7 @@ import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Flux;
import org.springframework.http.MediaType;
import org.springframework.http.codec.smile.JacksonSmileEncoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
@@ -37,7 +38,10 @@ import org.springframework.util.MimeType;
* @author Sebastien Deleuze
* @since 5.0
* @see Jackson2SmileDecoder
* @deprecated since 7.0 in favor of {@link JacksonSmileEncoder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2SmileEncoder extends AbstractJackson2Encoder {
private static final MimeType[] DEFAULT_SMILE_MIME_TYPES = new MimeType[] {

View File

@@ -50,7 +50,9 @@ import org.springframework.core.io.buffer.DataBufferUtils;
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 5.0
* @deprecated since 7.0 in favor of {@code org.springframework.http.codec.JacksonTokenizer}
*/
@Deprecated(since = "7.0", forRemoval = true)
final class Jackson2Tokenizer {
private final JsonParser parser;

View File

@@ -486,6 +486,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
* if configured by the application, to the given codec , including any
* codec it contains.
*/
@SuppressWarnings("removal")
private void initCodec(@Nullable Object codec) {
if (codec instanceof DecoderHttpMessageReader<?> decoderHttpMessageReader) {
codec = decoderHttpMessageReader.getDecoder();
@@ -612,6 +613,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
* Reset and initialize object readers.
* @since 5.3.3
*/
@SuppressWarnings("removal")
protected void initObjectReaders() {
this.objectReaders.clear();
if (!this.registerDefaults) {
@@ -760,6 +762,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
/**
* Return "base" object writers only, i.e. common to client and server.
*/
@SuppressWarnings("removal")
final List<HttpMessageWriter<?>> getBaseObjectWriters() {
List<HttpMessageWriter<?>> writers = new ArrayList<>();
if (kotlinSerializationCborPresent) {
@@ -839,6 +842,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
return this.jacksonJsonDecoder;
}
@SuppressWarnings("removal")
protected Decoder<?> getJackson2JsonDecoder() {
if (this.jackson2JsonDecoder == null) {
this.jackson2JsonDecoder = new Jackson2JsonDecoder();
@@ -853,6 +857,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
return this.jacksonJsonEncoder;
}
@SuppressWarnings("removal")
protected Encoder<?> getJackson2JsonEncoder() {
if (this.jackson2JsonEncoder == null) {
this.jackson2JsonEncoder = new Jackson2JsonEncoder();

View File

@@ -271,6 +271,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
}
@Override
@SuppressWarnings("removal")
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
if (!canWrite(mediaType)) {
return false;
@@ -328,6 +329,7 @@ public abstract class AbstractJacksonHttpMessageConverter extends AbstractSmartH
return readJavaType(javaType, inputMessage, null);
}
@SuppressWarnings("removal")
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage, @Nullable Map<String, Object> hints) throws IOException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = getCharset(contentType);

View File

@@ -39,7 +39,10 @@ import org.springframework.util.Assert;
*
* @author Sebastien Deleuze
* @since 5.0
* @deprecated since 7.0 in favor of {@link JacksonCborHttpMessageConverter}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class MappingJackson2CborHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
/**

View File

@@ -57,6 +57,7 @@ import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.ProblemDetail;
import org.springframework.http.converter.AbstractGenericHttpMessageConverter;
import org.springframework.http.converter.AbstractJacksonHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
@@ -78,7 +79,10 @@ import org.springframework.util.TypeUtils;
* @author Sam Brannen
* @since 4.1
* @see MappingJackson2HttpMessageConverter
* @deprecated since 7.0 in favor of {@link AbstractJacksonHttpMessageConverter}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public abstract class AbstractJackson2HttpMessageConverter extends AbstractGenericHttpMessageConverter<Object> {
private static final Map<String, JsonEncoding> ENCODINGS;

View File

@@ -100,8 +100,10 @@ import org.springframework.util.xml.StaxUtils;
* @since 4.1.1
* @see #build()
* @see #configure(ObjectMapper)
* @see Jackson2ObjectMapperFactoryBean
* @deprecated since 7.0 in favor using directly Jackson 3 builders like {@link tools.jackson.databind.json.JsonMapper#builder}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2ObjectMapperBuilder {
private static final boolean jackson2XmlPresent = ClassUtils.isPresent(

View File

@@ -136,7 +136,10 @@ import org.springframework.context.ApplicationContextAware;
* @author Tadaya Tsuyukubo
* @author Sebastien Deleuze
* @since 3.2
* @deprecated since 7.0 in favor of using directly Jackson 3 converters default constructor
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper>, BeanClassLoaderAware,
ApplicationContextAware, InitializingBean {

View File

@@ -35,6 +35,7 @@ import org.springframework.aot.hint.TypeHint.Builder;
*/
class JacksonModulesRuntimeHints implements RuntimeHintsRegistrar {
@SuppressWarnings("removal")
private static final Consumer<Builder> asJacksonModule = builder ->
builder.onReachableType(Jackson2ObjectMapperBuilder.class)
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);

View File

@@ -44,7 +44,10 @@ import org.springframework.http.MediaType;
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @since 3.1.2
* @deprecated since 7.0 in favor of {@link JacksonJsonHttpMessageConverter}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter {
private static final List<MediaType> problemDetailMediaTypes =

View File

@@ -30,7 +30,9 @@ import org.springframework.http.HttpInputMessage;
*
* @author Sebastien Deleuze
* @since 4.2
* @deprecated since 7.0 in favor of using {@link org.springframework.http.converter.SmartHttpMessageConverter} hints
*/
@Deprecated(since = "7.0", forRemoval = true)
public class MappingJacksonInputMessage implements HttpInputMessage {
private final InputStream body;

View File

@@ -33,7 +33,9 @@ import org.jspecify.annotations.Nullable;
*
* @author Rossen Stoyanchev
* @since 4.1
* @deprecated since 7.0 in favor of using {@link org.springframework.http.converter.SmartHttpMessageConverter} hints
*/
@Deprecated(since = "7.0", forRemoval = true)
public class MappingJacksonValue {
private Object value;

View File

@@ -38,7 +38,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;
/**
* Allows for creating Jackson ({@link JsonSerializer}, {@link JsonDeserializer},
* Allows for creating Jackson 2.x ({@link JsonSerializer}, {@link JsonDeserializer},
* {@link KeyDeserializer}, {@link TypeResolverBuilder}, {@link TypeIdResolver})
* beans with autowiring against a Spring {@link ApplicationContext}.
*
@@ -53,7 +53,9 @@ import org.springframework.util.Assert;
* @see Jackson2ObjectMapperBuilder#handlerInstantiator(HandlerInstantiator)
* @see ApplicationContext#getAutowireCapableBeanFactory()
* @see HandlerInstantiator
* @deprecated since 7.0 in favor of {@link org.springframework.http.support.JacksonHandlerInstantiator}
*/
@Deprecated(since = "7.0", forRemoval = true)
public class SpringHandlerInstantiator extends HandlerInstantiator {
private final AutowireCapableBeanFactory beanFactory;

View File

@@ -37,7 +37,10 @@ import org.springframework.util.Assert;
*
* @author Sebastien Deleuze
* @since 5.0
* @deprecated since 7.0 in favor of {@link JacksonSmileHttpMessageConverter}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class MappingJackson2SmileHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
/**

View File

@@ -101,6 +101,7 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv
}
@SuppressWarnings("removal")
public AllEncompassingFormHttpMessageConverter() {
if (jaxb2Present && !jacksonXmlPresent && !jackson2XmlPresent) {

View File

@@ -41,7 +41,10 @@ import org.springframework.util.Assert;
*
* @author Sebastien Deleuze
* @since 4.1
* @deprecated since 7.0 in favor of {@link JacksonXmlHttpMessageConverter}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
private static final List<MediaType> problemDetailMediaTypes =

View File

@@ -39,7 +39,10 @@ import org.springframework.util.Assert;
*
* @author Hyoungjune Kim
* @since 6.2
* @deprecated since 7.0 in favor of {@link JacksonYamlHttpMessageConverter}
*/
@Deprecated(since = "7.0", forRemoval = true)
@SuppressWarnings("removal")
public class MappingJackson2YamlHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
/**

View File

@@ -469,6 +469,7 @@ final class DefaultRestClientBuilder implements RestClient.Builder {
return this;
}
@SuppressWarnings("removal")
private List<HttpMessageConverter<?>> initMessageConverters() {
if (this.messageConverters == null) {
this.messageConverters = new ArrayList<>();

View File

@@ -202,6 +202,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
* Create a new instance with default settings.
* Default {@link HttpMessageConverter HttpMessageConverters} are initialized.
*/
@SuppressWarnings("removal")
public RestTemplate() {
this.messageConverters.add(new ByteArrayHttpMessageConverter());
this.messageConverters.add(new StringHttpMessageConverter());

View File

@@ -40,6 +40,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON;
*
* @author Sebastien Deleuze
*/
@SuppressWarnings("removal")
class Jackson2CborDecoderTests extends AbstractDecoderTests<Jackson2CborDecoder> {
private static final MimeType CBOR_MIME_TYPE = new MimeType("application", "cbor");

View File

@@ -43,6 +43,7 @@ import static org.springframework.http.MediaType.APPLICATION_XML;
*
* @author Sebastien Deleuze
*/
@SuppressWarnings("removal")
class Jackson2CborEncoderTests extends AbstractLeakCheckingTests {
private static final MimeType CBOR_MIME_TYPE = new MimeType("application", "cbor");

View File

@@ -62,6 +62,7 @@ import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
*/
@SuppressWarnings("removal")
class Jackson2JsonDecoderTests extends AbstractDecoderTests<Jackson2JsonDecoder> {
private final Pojo pojo1 = new Pojo("f1", "b1");

View File

@@ -50,12 +50,12 @@ 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_XML;
import static org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT;
/**
* Tests for {@link Jackson2JsonEncoder}.
* @author Sebastien Deleuze
*/
@SuppressWarnings("removal")
class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder> {
public Jackson2JsonEncoderTests() {
@@ -201,7 +201,8 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder>
Mono<JacksonViewBean> input = Mono.just(bean);
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView1.class);
Map<String, Object> hints = singletonMap(org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT,
MyJacksonView1.class);
testEncode(input, type, null, hints, step -> step
.consumeNextWith(expectString("{\"withView1\":\"with\"}"))
@@ -218,7 +219,8 @@ class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonEncoder>
Mono<JacksonViewBean> input = Mono.just(bean);
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView3.class);
Map<String, Object> hints = singletonMap(org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT,
MyJacksonView3.class);
testEncode(input, type, null, hints, step -> step
.consumeNextWith(expectString("{\"withoutView\":\"without\"}"))

View File

@@ -98,7 +98,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Eddú Meléndez
* @author Hyoungjune Kim
*/
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "removal"})
class Jackson2ObjectMapperBuilderTests {
private static final String DATE_FORMAT = "yyyy-MM-dd";

View File

@@ -61,6 +61,7 @@ import static org.assertj.core.api.Assertions.within;
* @author Sebastien Deleuze
* @author Juergen Hoeller
*/
@SuppressWarnings("removal")
class MappingJackson2HttpMessageConverterTests {
private final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();

View File

@@ -409,6 +409,7 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
@ParameterizedRestTemplateTest
@Disabled("Use RestClient + upcoming hint management instead")
@SuppressWarnings("removal")
void jsonPostForObjectWithJacksonJsonView(ClientHttpRequestFactory clientHttpRequestFactory) {
setUpClient(clientHttpRequestFactory);