Suppress Jackson 2 warnings

See gh-45535
This commit is contained in:
Phillip Webb
2025-05-13 11:42:25 -07:00
parent 5bdb0ecbb4
commit 02ee7fdb30
26 changed files with 34 additions and 2 deletions

View File

@@ -45,8 +45,7 @@ final class StandardGitHub implements GitHub {
@Override
public GitHubRepository getRepository(String organization, String name) {
RestTemplate restTemplate = new RestTemplate(
Collections.singletonList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
RestTemplate restTemplate = createRestTemplate();
restTemplate.getInterceptors().add((request, body, execution) -> {
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
request.getHeaders()
@@ -61,4 +60,9 @@ final class StandardGitHub implements GitHub {
return new StandardGitHubRepository(restTemplate);
}
@SuppressWarnings("removal")
private RestTemplate createRestTemplate() {
return new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
}
}

View File

@@ -38,6 +38,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
*/
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(JacksonAutoConfiguration.class)
@SuppressWarnings("removal")
public class JacksonEndpointAutoConfiguration {
@Bean

View File

@@ -180,6 +180,7 @@ public class WebFluxEndpointManagementContextConfiguration {
}
}
@SuppressWarnings("removal")
private void process(Encoder<?> encoder) {
if (encoder instanceof Jackson2JsonEncoder jackson2JsonEncoder) {
jackson2JsonEncoder.registerObjectMappersForType(OperationResponseBody.class, (associations) -> {

View File

@@ -151,6 +151,7 @@ public class WebMvcEndpointManagementContextConfiguration {
* {@link OperationResponseBody} to {@link MappingJackson2HttpMessageConverter}
* instances.
*/
@SuppressWarnings("removal")
static class EndpointObjectMapperWebMvcConfigurer implements WebMvcConfigurer {
private static final List<MediaType> MEDIA_TYPES = Collections
@@ -171,6 +172,7 @@ public class WebMvcEndpointManagementContextConfiguration {
}
}
@SuppressWarnings("removal")
private void configure(MappingJackson2HttpMessageConverter converter) {
converter.registerObjectMappersForType(OperationResponseBody.class, (associations) -> {
ObjectMapper objectMapper = this.endpointObjectMapper.get();

View File

@@ -37,6 +37,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
* @author Phillip Webb
*/
@Configuration
@SuppressWarnings("removal")
class EndpointObjectMapperConfiguration {
@Bean

View File

@@ -71,6 +71,7 @@ class AuditEventTests {
}
@Test
@SuppressWarnings("removal")
void jsonFormat() throws Exception {
AuditEvent event = new AuditEvent("johannes", "UNKNOWN",
Collections.singletonMap("type", (Object) "BadCredentials"));

View File

@@ -164,6 +164,7 @@ public class BackgroundPreinitializer implements ApplicationListener<SpringAppli
/**
* Early initializer for Jackson.
*/
@SuppressWarnings("removal")
private static final class JacksonInitializer implements Runnable {
@Override

View File

@@ -53,6 +53,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
@ConditionalOnClass(RepositoryRestMvcConfiguration.class)
@EnableConfigurationProperties(RepositoryRestProperties.class)
@Import(RepositoryRestMvcConfiguration.class)
@SuppressWarnings("removal")
public class RepositoryRestMvcAutoConfiguration {
@Bean

View File

@@ -34,6 +34,7 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
* @author Stephane Nicoll
*/
@Order(0)
@SuppressWarnings("removal")
class SpringBootRepositoryRestConfigurer implements RepositoryRestConfigurer {
private final Jackson2ObjectMapperBuilder objectMapperBuilder;

View File

@@ -54,6 +54,7 @@ public class GraphQlRSocketAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@SuppressWarnings("removal")
public GraphQlRSocketHandler graphQlRSocketHandler(ExecutionGraphQlService graphQlService,
ObjectProvider<RSocketGraphQlInterceptor> interceptors, ObjectMapper objectMapper) {
return new GraphQlRSocketHandler(graphQlService, interceptors.orderedStream().toList(),

View File

@@ -79,6 +79,7 @@ class GsonHttpMessageConvertersConfiguration {
super(ConfigurationPhase.REGISTER_BEAN);
}
@SuppressWarnings("removal")
@ConditionalOnBean(MappingJackson2HttpMessageConverter.class)
static class JacksonAvailable {

View File

@@ -200,6 +200,7 @@ public class HttpMessageConverters implements Iterable<HttpMessageConverter<?>>
return converters;
}
@SuppressWarnings("removal")
private void reorderXmlConvertersToEnd(List<HttpMessageConverter<?>> converters) {
List<HttpMessageConverter<?>> xml = new ArrayList<>();
for (Iterator<HttpMessageConverter<?>> iterator = converters.iterator(); iterator.hasNext();) {

View File

@@ -35,6 +35,7 @@ import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConve
* @author Andy Wilkinson
*/
@Configuration(proxyBeanMethods = false)
@SuppressWarnings("removal")
class JacksonHttpMessageConvertersConfiguration {
@Configuration(proxyBeanMethods = false)

View File

@@ -65,6 +65,7 @@ class JsonbHttpMessageConvertersConfiguration {
}
@SuppressWarnings("removal")
@ConditionalOnMissingBean({ MappingJackson2HttpMessageConverter.class, GsonHttpMessageConverter.class })
static class JacksonAndGsonMissing {

View File

@@ -54,6 +54,7 @@ public class CodecsAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ObjectMapper.class)
@SuppressWarnings("removal")
static class JacksonCodecConfiguration {
@Bean

View File

@@ -29,6 +29,7 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
* @since 1.4.0
*/
@FunctionalInterface
@SuppressWarnings("removal")
public interface Jackson2ObjectMapperBuilderCustomizer {
/**

View File

@@ -86,6 +86,7 @@ import org.springframework.util.ReflectionUtils;
*/
@AutoConfiguration
@ConditionalOnClass(ObjectMapper.class)
@SuppressWarnings("removal")
public class JacksonAutoConfiguration {
private static final Map<?, Boolean> FEATURE_DEFAULTS;

View File

@@ -66,6 +66,7 @@ public class RSocketStrategiesAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ObjectMapper.class, CBORFactory.class })
@SuppressWarnings("removal")
protected static class JacksonCborStrategyConfiguration {
private static final MediaType[] SUPPORTED_TYPES = { MediaType.APPLICATION_CBOR };
@@ -85,6 +86,7 @@ public class RSocketStrategiesAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ObjectMapper.class)
@SuppressWarnings("removal")
protected static class JacksonJsonStrategyConfiguration {
private static final MediaType[] SUPPORTED_TYPES = { MediaType.APPLICATION_JSON,

View File

@@ -83,6 +83,7 @@ public class WebSocketMessagingAutoConfiguration {
@Override
public boolean configureMessageConverters(List<MessageConverter> messageConverters) {
@SuppressWarnings("removal")
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(this.objectMapper);
DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);

View File

@@ -161,6 +161,7 @@ class RepositoryRestMvcAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(City.class)
@EnableWebMvc
@SuppressWarnings("removal")
static class TestConfigurationWithObjectMapperBuilder {
@Bean

View File

@@ -88,6 +88,7 @@ class HypermediaAutoConfigurationTests {
}
@Test
@SuppressWarnings("removal")
void whenUsingTheDefaultConfigurationThenMappingJacksonConverterCanWriteHateoasTypeAsApplicationJson() {
this.contextRunner.run((context) -> {
RequestMappingHandlerAdapter handlerAdapter = context.getBean(RequestMappingHandlerAdapter.class);
@@ -102,6 +103,7 @@ class HypermediaAutoConfigurationTests {
}
@Test
@SuppressWarnings("removal")
void whenHalIsNotTheDefaultJsonMediaTypeThenMappingJacksonConverterCannotWriteHateoasTypeAsApplicationJson() {
this.contextRunner.withPropertyValues("spring.hateoas.use-hal-as-default-json-media-type:false")
.run((context) -> {

View File

@@ -68,6 +68,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Moritz Halbritter
* @author Sebastien Deleuze
*/
@SuppressWarnings("removal")
class HttpMessageConvertersAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()

View File

@@ -44,6 +44,7 @@ import static org.mockito.Mockito.mock;
* @author Dave Syer
* @author Phillip Webb
*/
@SuppressWarnings("removal")
class HttpMessageConvertersTests {
@Test

View File

@@ -92,6 +92,7 @@ import static org.mockito.Mockito.mock;
* @author Ralf Ueberfuhr
* @author Eddú Meléndez
*/
@SuppressWarnings("removal")
class JacksonAutoConfigurationTests {
protected final ApplicationContextRunner contextRunner = new ApplicationContextRunner()

View File

@@ -49,6 +49,7 @@ class RSocketStrategiesAutoConfigurationTests {
AutoConfigurations.of(JacksonAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class));
@Test
@SuppressWarnings("removal")
void shouldCreateDefaultBeans() {
this.contextRunner.run((context) -> {
assertThat(context).getBeans(RSocketStrategies.class).hasSize(1);

View File

@@ -186,6 +186,7 @@ class WebMvcTypeExcludeFilterTests {
}
@SuppressWarnings("removal")
static class ExampleMessageConverter extends MappingJackson2HttpMessageConverter {
}