mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-24 07:39:09 +00:00
Register overrides in HttpMessageConverters when defaults are off
Prior to this commit, all `with**Converter` methods in `HttpMessageConverters` builders would only apply if the `registerDefaults()` option is on. While the original intent is to allow overrides for auto-detected defaults, this creates an unnecessary discrepancy with `addCustomConverter` which is always effective. Allowing sich registrations when defaults are off should not introduce invalid states and only reflects the intent of the developer. This commit now allows such cases. Fixes gh-36579
This commit is contained in:
+10
-5
@@ -177,10 +177,13 @@ class DefaultHttpMessageConvertersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotConfigureOverridesWhenDefaultOff() {
|
||||
void shouldConfigureOverridesWhenDefaultOff() {
|
||||
var stringConverter = new StringHttpMessageConverter();
|
||||
var converters = HttpMessageConverters.forClient().withStringConverter(stringConverter).build();
|
||||
assertThat(converters).isEmpty();
|
||||
assertThat(converters).hasExactlyElementsOfTypes(
|
||||
StringHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class);
|
||||
var configured = findMessageConverter(StringHttpMessageConverter.class, converters);
|
||||
assertThat(configured).isEqualTo(stringConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -309,12 +312,14 @@ class DefaultHttpMessageConvertersTests {
|
||||
assertThat(multipartConverter.getPartConverters()).hasAtLeastOneElementOfType(CustomHttpMessageConverter.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void shouldNotConfigureOverridesWhenDefaultOff() {
|
||||
void shouldConfigureOverridesWhenDefaultOff() {
|
||||
var stringConverter = new StringHttpMessageConverter();
|
||||
var converters = HttpMessageConverters.forServer().withStringConverter(stringConverter).build();
|
||||
assertThat(converters).isEmpty();
|
||||
assertThat(converters).hasExactlyElementsOfTypes(
|
||||
StringHttpMessageConverter.class, AllEncompassingFormHttpMessageConverter.class);
|
||||
var configured = findMessageConverter(StringHttpMessageConverter.class, converters);
|
||||
assertThat(configured).isEqualTo(stringConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user