Skip to content

Commit 379b2ce

Browse files
committed
Fix Eclipse warnings caused by deprecation of Jackson 2 support
See gh-45535
1 parent ee90996 commit 379b2ce

File tree

16 files changed

+70
-79
lines changed

16 files changed

+70
-79
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,6 @@
6565
import org.springframework.http.codec.EncoderHttpMessageWriter;
6666
import org.springframework.http.codec.HttpMessageWriter;
6767
import org.springframework.http.codec.ServerCodecConfigurer;
68-
import org.springframework.http.codec.json.Jackson2JsonEncoder;
6968
import org.springframework.http.server.reactive.HttpHandler;
7069
import org.springframework.util.StringUtils;
7170
import org.springframework.util.function.SingletonSupplier;
@@ -150,7 +149,8 @@ static ServerCodecConfigurerEndpointObjectMapperBeanPostProcessor serverCodecCon
150149

151150
/**
152151
* {@link BeanPostProcessor} to apply {@link EndpointObjectMapper} for
153-
* {@link OperationResponseBody} to {@link Jackson2JsonEncoder} instances.
152+
* {@link OperationResponseBody} to
153+
* {@link org.springframework.http.codec.json.Jackson2JsonEncoder} instances.
154154
*/
155155
static class ServerCodecConfigurerEndpointObjectMapperBeanPostProcessor implements BeanPostProcessor {
156156

@@ -180,9 +180,9 @@ private void process(ServerCodecConfigurer configurer) {
180180
}
181181
}
182182

183-
@SuppressWarnings("removal")
183+
@SuppressWarnings({ "removal", "deprecation" })
184184
private void process(Encoder<?> encoder) {
185-
if (encoder instanceof Jackson2JsonEncoder jackson2JsonEncoder) {
185+
if (encoder instanceof org.springframework.http.codec.json.Jackson2JsonEncoder jackson2JsonEncoder) {
186186
jackson2JsonEncoder.registerObjectMappersForType(OperationResponseBody.class, (associations) -> {
187187
ObjectMapper objectMapper = this.endpointObjectMapper.get().get();
188188
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, objectMapper));

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.springframework.core.env.Environment;
5959
import org.springframework.http.MediaType;
6060
import org.springframework.http.converter.HttpMessageConverter;
61-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
6261
import org.springframework.util.StringUtils;
6362
import org.springframework.web.servlet.DispatcherServlet;
6463
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -148,7 +147,8 @@ static EndpointObjectMapperWebMvcConfigurer endpointObjectMapperWebMvcConfigurer
148147

149148
/**
150149
* {@link WebMvcConfigurer} to apply {@link EndpointObjectMapper} for
151-
* {@link OperationResponseBody} to {@link MappingJackson2HttpMessageConverter}
150+
* {@link OperationResponseBody} to
151+
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}
152152
* instances.
153153
*/
154154
@SuppressWarnings("removal")
@@ -166,14 +166,14 @@ static class EndpointObjectMapperWebMvcConfigurer implements WebMvcConfigurer {
166166
@Override
167167
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
168168
for (HttpMessageConverter<?> converter : converters) {
169-
if (converter instanceof MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter) {
169+
if (converter instanceof org.springframework.http.converter.json.MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter) {
170170
configure(mappingJackson2HttpMessageConverter);
171171
}
172172
}
173173
}
174174

175-
@SuppressWarnings("removal")
176-
private void configure(MappingJackson2HttpMessageConverter converter) {
175+
@SuppressWarnings({ "removal", "deprecation" })
176+
private void configure(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter converter) {
177177
converter.registerObjectMappersForType(OperationResponseBody.class, (associations) -> {
178178
ObjectMapper objectMapper = this.endpointObjectMapper.get();
179179
MEDIA_TYPES.forEach((mimeType) -> associations.put(mimeType, objectMapper));

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.json.JSONObject;
2222
import org.junit.jupiter.api.Test;
2323

24-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
25-
2624
import static org.assertj.core.api.Assertions.assertThat;
2725
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
2826

@@ -71,11 +69,13 @@ void nullType() {
7169
}
7270

7371
@Test
74-
@SuppressWarnings("removal")
72+
@SuppressWarnings({ "removal", "deprecation" })
7573
void jsonFormat() throws Exception {
7674
AuditEvent event = new AuditEvent("johannes", "UNKNOWN",
7775
Collections.singletonMap("type", (Object) "BadCredentials"));
78-
String json = Jackson2ObjectMapperBuilder.json().build().writeValueAsString(event);
76+
String json = org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.json()
77+
.build()
78+
.writeValueAsString(event);
7979
JSONObject jsonObject = new JSONObject(json);
8080
assertThat(jsonObject.getString("type")).isEqualTo("UNKNOWN");
8181
assertThat(jsonObject.getJSONObject("data").getString("type")).isEqualTo("BadCredentials");

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,6 @@
3535
import org.springframework.core.NativeDetector;
3636
import org.springframework.core.Ordered;
3737
import org.springframework.format.support.DefaultFormattingConversionService;
38-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3938
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
4039

4140
/**
@@ -164,12 +163,12 @@ public void run() {
164163
/**
165164
* Early initializer for Jackson.
166165
*/
167-
@SuppressWarnings("removal")
166+
@SuppressWarnings({ "removal", "deprecation" })
168167
private static final class JacksonInitializer implements Runnable {
169168

170169
@Override
171170
public void run() {
172-
Jackson2ObjectMapperBuilder.json().build();
171+
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.json().build();
173172
}
174173

175174
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/rsocket/GraphQlRSocketAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.graphql.execution.GraphQlSource;
3737
import org.springframework.graphql.server.GraphQlRSocketHandler;
3838
import org.springframework.graphql.server.RSocketGraphQlInterceptor;
39-
import org.springframework.http.codec.json.Jackson2JsonEncoder;
4039
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
4140

4241
/**
@@ -54,11 +53,11 @@ public class GraphQlRSocketAutoConfiguration {
5453

5554
@Bean
5655
@ConditionalOnMissingBean
57-
@SuppressWarnings("removal")
56+
@SuppressWarnings({ "removal", "deprecation" })
5857
public GraphQlRSocketHandler graphQlRSocketHandler(ExecutionGraphQlService graphQlService,
5958
ObjectProvider<RSocketGraphQlInterceptor> interceptors, ObjectMapper objectMapper) {
6059
return new GraphQlRSocketHandler(graphQlService, interceptors.orderedStream().toList(),
61-
new Jackson2JsonEncoder(objectMapper));
60+
new org.springframework.http.codec.json.Jackson2JsonEncoder(objectMapper));
6261
}
6362

6463
@Bean

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/GsonHttpMessageConvertersConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.context.annotation.Conditional;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.http.converter.json.GsonHttpMessageConverter;
31-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
3231

3332
/**
3433
* Configuration for HTTP Message converters that use Gson.
@@ -79,8 +78,8 @@ private static class JacksonAndJsonbUnavailableCondition extends NoneNestedCondi
7978
super(ConfigurationPhase.REGISTER_BEAN);
8079
}
8180

82-
@SuppressWarnings("removal")
83-
@ConditionalOnBean(MappingJackson2HttpMessageConverter.class)
81+
@SuppressWarnings({ "deprecation", "removal" })
82+
@ConditionalOnBean(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.class)
8483
static class JacksonAvailable {
8584

8685
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConverters.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
2828
import org.springframework.http.converter.HttpMessageConverter;
2929
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
3030
import org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter;
31-
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
3231
import org.springframework.util.ClassUtils;
3332
import org.springframework.web.client.RestTemplate;
3433
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@@ -206,7 +205,7 @@ private void reorderXmlConvertersToEnd(List<HttpMessageConverter<?>> converters)
206205
for (Iterator<HttpMessageConverter<?>> iterator = converters.iterator(); iterator.hasNext();) {
207206
HttpMessageConverter<?> converter = iterator.next();
208207
if ((converter instanceof AbstractXmlHttpMessageConverter)
209-
|| (converter instanceof MappingJackson2XmlHttpMessageConverter)) {
208+
|| (converter instanceof org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)) {
210209
xml.add(converter);
211210
iterator.remove();
212211
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/JsonbHttpMessageConvertersConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.context.annotation.Configuration;
2929
import org.springframework.http.converter.json.GsonHttpMessageConverter;
3030
import org.springframework.http.converter.json.JsonbHttpMessageConverter;
31-
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
3231

3332
/**
3433
* Configuration for HTTP Message converters that use JSON-B.
@@ -66,7 +65,8 @@ static class JsonbPreferred {
6665
}
6766

6867
@SuppressWarnings("removal")
69-
@ConditionalOnMissingBean({ MappingJackson2HttpMessageConverter.class, GsonHttpMessageConverter.class })
68+
@ConditionalOnMissingBean({ org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.class,
69+
GsonHttpMessageConverter.class })
7070
static class JacksonAndGsonMissing {
7171

7272
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/codec/CodecsAutoConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.springframework.core.annotation.Order;
3333
import org.springframework.core.env.Environment;
3434
import org.springframework.http.codec.CodecConfigurer;
35-
import org.springframework.http.codec.json.Jackson2JsonDecoder;
36-
import org.springframework.http.codec.json.Jackson2JsonEncoder;
3735
import org.springframework.util.MimeType;
3836
import org.springframework.util.unit.DataSize;
3937
import org.springframework.web.reactive.function.client.WebClient;
@@ -54,7 +52,7 @@ public class CodecsAutoConfiguration {
5452

5553
@Configuration(proxyBeanMethods = false)
5654
@ConditionalOnClass(ObjectMapper.class)
57-
@SuppressWarnings("removal")
55+
@SuppressWarnings({ "removal", "deprecation" })
5856
static class JacksonCodecConfiguration {
5957

6058
@Bean
@@ -63,8 +61,10 @@ static class JacksonCodecConfiguration {
6361
CodecCustomizer jacksonCodecCustomizer(ObjectMapper objectMapper) {
6462
return (configurer) -> {
6563
CodecConfigurer.DefaultCodecs defaults = configurer.defaultCodecs();
66-
defaults.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, EMPTY_MIME_TYPES));
67-
defaults.jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, EMPTY_MIME_TYPES));
64+
defaults.jackson2JsonDecoder(
65+
new org.springframework.http.codec.json.Jackson2JsonDecoder(objectMapper, EMPTY_MIME_TYPES));
66+
defaults.jackson2JsonEncoder(
67+
new org.springframework.http.codec.json.Jackson2JsonEncoder(objectMapper, EMPTY_MIME_TYPES));
6868
};
6969
}
7070

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketStrategiesAutoConfiguration.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,11 +32,6 @@
3232
import org.springframework.context.annotation.Configuration;
3333
import org.springframework.core.annotation.Order;
3434
import org.springframework.http.MediaType;
35-
import org.springframework.http.codec.cbor.Jackson2CborDecoder;
36-
import org.springframework.http.codec.cbor.Jackson2CborEncoder;
37-
import org.springframework.http.codec.json.Jackson2JsonDecoder;
38-
import org.springframework.http.codec.json.Jackson2JsonEncoder;
39-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
4035
import org.springframework.messaging.rsocket.RSocketStrategies;
4136
import org.springframework.util.ClassUtils;
4237
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
@@ -66,27 +61,30 @@ public RSocketStrategies rSocketStrategies(ObjectProvider<RSocketStrategiesCusto
6661

6762
@Configuration(proxyBeanMethods = false)
6863
@ConditionalOnClass({ ObjectMapper.class, CBORFactory.class })
69-
@SuppressWarnings("removal")
64+
@SuppressWarnings({ "removal", "deprecation" })
7065
protected static class JacksonCborStrategyConfiguration {
7166

7267
private static final MediaType[] SUPPORTED_TYPES = { MediaType.APPLICATION_CBOR };
7368

7469
@Bean
7570
@Order(0)
76-
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
77-
public RSocketStrategiesCustomizer jacksonCborRSocketStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
71+
@ConditionalOnBean(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.class)
72+
public RSocketStrategiesCustomizer jacksonCborRSocketStrategyCustomizer(
73+
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder builder) {
7874
return (strategy) -> {
7975
ObjectMapper objectMapper = builder.createXmlMapper(false).factory(new CBORFactory()).build();
80-
strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
81-
strategy.encoder(new Jackson2CborEncoder(objectMapper, SUPPORTED_TYPES));
76+
strategy.decoder(
77+
new org.springframework.http.codec.cbor.Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
78+
strategy.encoder(
79+
new org.springframework.http.codec.cbor.Jackson2CborEncoder(objectMapper, SUPPORTED_TYPES));
8280
};
8381
}
8482

8583
}
8684

8785
@Configuration(proxyBeanMethods = false)
8886
@ConditionalOnClass(ObjectMapper.class)
89-
@SuppressWarnings("removal")
87+
@SuppressWarnings({ "removal", "deprecation" })
9088
protected static class JacksonJsonStrategyConfiguration {
9189

9290
private static final MediaType[] SUPPORTED_TYPES = { MediaType.APPLICATION_JSON,
@@ -97,8 +95,10 @@ protected static class JacksonJsonStrategyConfiguration {
9795
@ConditionalOnBean(ObjectMapper.class)
9896
public RSocketStrategiesCustomizer jacksonJsonRSocketStrategyCustomizer(ObjectMapper objectMapper) {
9997
return (strategy) -> {
100-
strategy.decoder(new Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES));
101-
strategy.encoder(new Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES));
98+
strategy.decoder(
99+
new org.springframework.http.codec.json.Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES));
100+
strategy.encoder(
101+
new org.springframework.http.codec.json.Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES));
102102
};
103103
}
104104

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,6 @@
3636
import org.springframework.core.task.AsyncTaskExecutor;
3737
import org.springframework.messaging.converter.ByteArrayMessageConverter;
3838
import org.springframework.messaging.converter.DefaultContentTypeResolver;
39-
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
4039
import org.springframework.messaging.converter.MessageConverter;
4140
import org.springframework.messaging.converter.StringMessageConverter;
4241
import org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration;
@@ -83,8 +82,9 @@ private static AsyncTaskExecutor determineAsyncTaskExecutor(Map<String, AsyncTas
8382

8483
@Override
8584
public boolean configureMessageConverters(List<MessageConverter> messageConverters) {
86-
@SuppressWarnings("removal")
87-
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(this.objectMapper);
85+
@SuppressWarnings({ "removal", "deprecation" })
86+
org.springframework.messaging.converter.MappingJackson2MessageConverter converter = new org.springframework.messaging.converter.MappingJackson2MessageConverter(
87+
this.objectMapper);
8888
DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
8989
resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
9090
converter.setContentTypeResolver(resolver);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,6 @@
4040
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
4141
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
4242
import org.springframework.http.MediaType;
43-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
4443
import org.springframework.mock.web.MockServletContext;
4544
import org.springframework.web.servlet.config.annotation.CorsRegistry;
4645
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -161,12 +160,12 @@ static class TestConfigurationWithRestMvcConfig {
161160
@Configuration(proxyBeanMethods = false)
162161
@TestAutoConfigurationPackage(City.class)
163162
@EnableWebMvc
164-
@SuppressWarnings("removal")
163+
@SuppressWarnings({ "removal", "deprecation" })
165164
static class TestConfigurationWithObjectMapperBuilder {
166165

167166
@Bean
168-
Jackson2ObjectMapperBuilder objectMapperBuilder() {
169-
Jackson2ObjectMapperBuilder objectMapperBuilder = new Jackson2ObjectMapperBuilder();
167+
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder objectMapperBuilder() {
168+
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder objectMapperBuilder = new org.springframework.http.converter.json.Jackson2ObjectMapperBuilder();
170169
objectMapperBuilder.simpleDateFormat("yyyy-MM");
171170
return objectMapperBuilder;
172171
}

0 commit comments

Comments
 (0)