Skip to content

Converter overrides in HttpMessageConverters only apply when defaults are registered #36579

Closed

Description

@jbl428
/**
 * Override the default Jackson 3.x JSON {@code HttpMessageConverter}
 * with any converter supporting the JSON format.
 * @param jsonMessageConverter the converter instance to use
 * @see org.springframework.http.converter.json.JacksonJsonHttpMessageConverter
 */
T withJsonConverter(HttpMessageConverter<?> jsonMessageConverter);

I initially looked only at the Javadoc and assumed that overriding the JSON converter would register it unconditionally. After checking the implementation, I found that this is not the case: when registerDefaults() is not enabled, withJsonConverter(...) and similar methods are ignored and no converter is registered.

@Bean
fun groupConfigurer(objectMapper: JsonMapper): RestClientHttpServiceGroupConfigurer =
    RestClientHttpServiceGroupConfigurer { groups ->
        groups.forEachClient { _, builder ->
            builder
                .configureMessageConverters {
                    it.withJsonConverter(JacksonJsonHttpMessageConverter(objectMapper))
                }
        }
    }

In this example, the order looks valid at a glance, but the specific converter registration only takes effect if registerDefaults() has already been enabled.

This matches the concern raised in the discussion on issue #35704, where it was
noted that the Javadoc should explicitly state that these format-specific converter
methods are intended to customize default registrations, and are ignored when default
registrations are turned off. That clarification does not appear to be reflected in
the current Javadoc yet.

It would be helpful to update the Javadoc to explicitly document this behavior,
so that users are not misled into expecting unconditional registration.

Activity

  1. self-assigned this
    on Apr 1, 2026
  2. bclozel commented on Apr 1, 2026

    @bclozel
    Member

    I've reviewed the conversation in #35704 and use cases similar to this one.

    So far we tried to favor consistency with the reactive codecs, which are organized in two groups, DefaultCodecs and CustomCodecs. With HttpMessageConverters, our use cases didn't require this level of indirection because we don't have to offer specific configuration options for each group. This makes the API surface flatter and consider converters as a single collection.

    Comments in #35704 also point out that the ordering of converters has less meaning if defaults aren't activated. I have changed my mind about this because customizing HttpMessageConverters can happen in many independent places and having to call registerDefaults() in each place (to ensure that our customization is effective) is not consistent with the overall API design.

    I'm repurposing this issue to adapt the behavior here and not require the registration of defaults when overrides are provided. This also aligns with the existing behavior when using addCustomConverter.

  3. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    and removed on Apr 1, 2026
  4. changed the title [-]Clarify format-specific converter methods require registerDefaults() in HttpMessageConverters[/-] [+]Converter overrides in HttpMessageConverters only apply when defaults are registered[/+] on Apr 1, 2026
  5. added this to the 7.0.7 milestone on Apr 1, 2026
  6. added a commit that references this issue on Apr 1, 2026
    aebf7c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions