Skip to content

Can no longer override JacksonJsonHttpMessageConverter with ServerHttpMessageConvertersCustomizer #48609

@gkiel

Description

@gkiel

As of spring boot 4.0.0, I was able to add the following:

@Bean
ServerHttpMessageConvertersCustomizer jacksonCustomizer(JsonMapper jsonMapper) {
    return builder -> builder.withJsonConverter(
                new JacksonJsonHttpMessageConverter(jsonMapper.rebuild()
                    .addModule(<some module with custom serializers>)
                    .build())
            );
}

to customize the object mapper used to serialize our api responses, while not applying those custom serializers to the RestClients used in our application.

However, with 4.0.1, this customizer no longer works since it's now competing with the one added in 50f64f9 and since these customizers are modifying a builder, the last one wins, and the order of that new one is defaulting to LOWEST_PRECEDENCE, meaning it'll always win.

I've been able to work around it by adding:

spring:
  http:
    converters:
      preferred-json-mapper: none

to my application.yml and supplying a ClientHttpMessageConvertersCustomizer that uses an object mapper without those additional serializers, but that seems rather clunky.

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions