diff --git a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java index db03383e16c..995863e5d1a 100644 --- a/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java +++ b/module/spring-boot-http-converter/src/main/java/org/springframework/boot/http/converter/autoconfigure/DefaultClientHttpMessageConvertersCustomizer.java @@ -33,7 +33,6 @@ class DefaultClientHttpMessageConvertersCustomizer implements ClientHttpMessageC DefaultClientHttpMessageConvertersCustomizer(@Nullable HttpMessageConverters legacyConverters, Collection> converters) { - this.legacyConverters = legacyConverters; this.converters = converters; } diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/RestClientAutoConfiguration.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/RestClientAutoConfiguration.java index 94abc89c64b..e7170fc78a7 100644 --- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/RestClientAutoConfiguration.java +++ b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/RestClientAutoConfiguration.java @@ -29,6 +29,7 @@ import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder; import org.springframework.boot.http.client.HttpClientSettings; import org.springframework.boot.http.client.autoconfigure.imperative.ImperativeHttpClientAutoConfiguration; import org.springframework.boot.http.converter.autoconfigure.ClientHttpMessageConvertersCustomizer; +import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.restclient.RestClientCustomizer; import org.springframework.boot.ssl.SslBundles; import org.springframework.context.annotation.Bean; @@ -54,7 +55,7 @@ import org.springframework.web.client.RestClient.Builder; * @since 4.0.0 */ @AutoConfiguration(after = { ImperativeHttpClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class, - SslAutoConfiguration.class }) + SslAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) @ConditionalOnClass(RestClient.class) public final class RestClientAutoConfiguration { diff --git a/settings.gradle b/settings.gradle index e82d310b062..378bee883ab 100644 --- a/settings.gradle +++ b/settings.gradle @@ -438,6 +438,7 @@ include ":smoke-test:spring-boot-smoke-test-pulsar" include ":smoke-test:spring-boot-smoke-test-quartz" include ":smoke-test:spring-boot-smoke-test-reactive-oauth2-client" include ":smoke-test:spring-boot-smoke-test-reactive-oauth2-resource-server" +include ":smoke-test:spring-boot-smoke-test-restclient" include ":smoke-test:spring-boot-smoke-test-rsocket" include ":smoke-test:spring-boot-smoke-test-saml2-service-provider" include ":smoke-test:spring-boot-smoke-test-secure" diff --git a/smoke-test/spring-boot-smoke-test-restclient/build.gradle b/smoke-test/spring-boot-smoke-test-restclient/build.gradle new file mode 100644 index 00000000000..c7334f391b6 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/build.gradle @@ -0,0 +1,31 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id "java" +} + +description = "Spring Boot Rest Client smoke test" + +dependencies { + implementation(project(":starter:spring-boot-starter-restclient")) + + testImplementation(project(":starter:spring-boot-starter-test")) +} + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/smoke-test/spring-boot-smoke-test-restclient/src/main/java/aaaa/Gh49223AutoConfiguration.java b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/aaaa/Gh49223AutoConfiguration.java new file mode 100644 index 00000000000..faef311aada --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/aaaa/Gh49223AutoConfiguration.java @@ -0,0 +1,11 @@ +package aaaa; + +import org.springframework.boot.autoconfigure.AutoConfiguration; + +@AutoConfiguration(afterName = { "org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration", + "org.springframework.boot.restclient.autoconfigure.RestTemplateAutoConfiguration" }) +class Gh49223AutoConfiguration { + + // Class must be in a package name that is ordered early + +} \ No newline at end of file diff --git a/smoke-test/spring-boot-smoke-test-restclient/src/main/java/aaaa/package-info.java b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/aaaa/package-info.java new file mode 100644 index 00000000000..3b1fafc30f7 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/aaaa/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@NullMarked +package aaaa; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-restclient/src/main/java/smoketest/restclient/SampleRestClientApplication.java b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/smoketest/restclient/SampleRestClientApplication.java new file mode 100644 index 00000000000..1456312bd21 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/smoketest/restclient/SampleRestClientApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.restclient; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleRestClientApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleRestClientApplication.class, args); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-restclient/src/main/java/smoketest/restclient/package-info.java b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/smoketest/restclient/package-info.java new file mode 100644 index 00000000000..4321ead51ba --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/src/main/java/smoketest/restclient/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@NullMarked +package smoketest.restclient; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-restclient/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/smoke-test/spring-boot-smoke-test-restclient/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000000..aa4633e150f --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +aaaa.Gh49223AutoConfiguration diff --git a/smoke-test/spring-boot-smoke-test-restclient/src/test/java/smoketest/restclient/SampleRestClientApplicationGh49223Tests.java b/smoke-test/spring-boot-smoke-test-restclient/src/test/java/smoketest/restclient/SampleRestClientApplicationGh49223Tests.java new file mode 100644 index 00000000000..0e750b7b6c9 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-restclient/src/test/java/smoketest/restclient/SampleRestClientApplicationGh49223Tests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.restclient; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import tools.jackson.databind.DeserializationFeature; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.converter.json.JacksonJsonHttpMessageConverter; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.web.client.RestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(properties = "spring.jackson.deserialization.fail-on-null-for-primitives=false") +class SampleRestClientApplicationGh49223Tests { + + @Autowired + private RestClient.Builder restClientBuilder; + + @Test + void applicationStarts() { + RestClient restClient = this.restClientBuilder.build(); + List messageConverters = (List) ReflectionTestUtils.getField(restClient, "messageConverters"); + JacksonJsonHttpMessageConverter jacksonConverter = (JacksonJsonHttpMessageConverter) messageConverters.stream() + .filter((converter) -> converter instanceof JacksonJsonHttpMessageConverter) + .findFirst() + .orElseThrow(); + assertThat(jacksonConverter.getMapper().isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) + .isFalse(); + } + +}