Skip to content

Fix Feign JSON converter to use application JsonMapper modules - #1399

Open
arimu1 wants to merge 1 commit into
spring-cloud:mainfrom
arimu1:fix/1376-jsonmapper-modules
Open

Fix Feign JSON converter to use application JsonMapper modules#1399
arimu1 wants to merge 1 commit into
spring-cloud:mainfrom
arimu1:fix/1376-jsonmapper-modules

Conversation

@arimu1

@arimu1 arimu1 commented Aug 7, 2026

Copy link
Copy Markdown

Motivation and Context

Fixes #1376 — Feign could not deserialize types that need Jackson modules registered as beans (e.g. JavaxMoneyModule / MonetaryAmount), while the same app's @RestController worked.

FeignHttpMessageConverters called registerDefaults(), which can install a classpath-default JacksonJsonHttpMessageConverter whose mapper does not include application JacksonModule beans. Boot's ClientHttpMessageConvertersCustomizer path is not always enough for Feign child contexts; the proven workaround was a late HttpMessageConverterCustomizer that reinstalls a converter backed by the application JsonMapper.

How has this been tested?

  • Unit: FeignHttpMessageConvertersTests (concurrent init + application JsonMapper / module coverage) — 2/2 (Temurin 21)
  • ./mvnw -pl spring-cloud-openfeign-core test -Dtest=FeignHttpMessageConvertersTests -Pspring

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Changes

  • After applying ClientHttpMessageConvertersCustomizers, apply the application JsonMapper (when present) via withJsonConverter, so Feign uses the same modules as MVC.
  • Resolve JsonMapper via BeanFactory without requiring Jackson on the configuration class classpath.
  • Regression test with a synthetic abstract type + JacksonModule (stand-in for money types).

registerDefaults() may install a classpath-default Jackson mapper that
does not include JacksonModule beans (e.g. JavaxMoneyModule). Wire the
application JsonMapper into FeignHttpMessageConverters after Boot
ClientHttpMessageConvertersCustomizers so Feign deserializes the same
types as MVC.

Fixes spring-cloudgh-1376

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MonetaryAmount not deserialized by Feign client despite JavaxMoneyModule registered as @Bean (Spring Boot 4 / Jackson 3)

2 participants