Skip to content

Use configured JsonMapper bean when resolving JacksonJsonSerde - #3243

Open
adityaanikam wants to merge 1 commit into
spring-cloud:mainfrom
adityaanikam:jackson-json-mapper-bean-3231
Open

Use configured JsonMapper bean when resolving JacksonJsonSerde#3243
adityaanikam wants to merge 1 commit into
spring-cloud:mainfrom
adityaanikam:jackson-json-mapper-bean-3231

Conversation

@adityaanikam

Copy link
Copy Markdown

Fixes gh-3231

What / why

SerdeResolverUtils.resolveForType() falls back to new JacksonJsonSerde<>(genericRawClazz) (the no-arg-mapper constructor) whenever no matching Serde bean and no valid fallback are found. This means any JsonMapper bean configured in the application context — for spring.jackson.* customization or otherwise — is never picked up for Serdes created through this path, even though JacksonJsonSerde has a (Class, JsonMapper) constructor that supports exactly this.

Fix

Look up a JsonMapper bean from the context (context.getBeanProvider(JsonMapper.class).getIfUnique()) and pass it into JacksonJsonSerde's constructor when exactly one unambiguous bean is present, falling back to today's no-arg behavior otherwise (zero or multiple candidates).

Testing

Added SerdeResolverUtilsTests.ResolveForType.NoMatchingSerdeBeans.WithJsonMapperBean, which registers a custom JsonMapper bean and verifies (via the JacksonJsonSerializer internal field) that the exact same instance is wired into the resolved Serde. Ran the full spring-cloud-stream-binder-kafka-streams test suite locally (122 tests, 0 failures, 0 errors) to confirm no regressions.

Fixes spring-cloudgh-3231

Signed-off-by: adityaanikam <adityanikam9502@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spring cloud stream - JacksonJsonSerde does not have mechanism to override JSON mapper config

1 participant