Skip to content

GH-4442: Fix value serializer mappings for different classloaders#4460

Merged
artembilan merged 1 commit into
spring-projects:mainfrom
sobychacko:gh-4442
Jun 1, 2026
Merged

GH-4442: Fix value serializer mappings for different classloaders#4460
artembilan merged 1 commit into
spring-projects:mainfrom
sobychacko:gh-4442

Conversation

@sobychacko

Copy link
Copy Markdown
Contributor

Fixes: #4442

When the type mapper is initialized under one classloader and messages are produced under another (e.g. Spring DevTools restart classloader), the reverse lookup map keyed on Class<?> identity misses the entry because two Class<?> objects representing the same class loaded by different classloaders are not equal in a HashMap lookup. The fallback writes the FQCN header instead of the configured alias, silently breaking consumers that depend on the alias.

Fix by changing the reverse map key from Class<?> to String (using clazz.getName()), which is classloader-agnostic.

The same change is applied to the deprecated AbstractJavaTypeMapper for Jackson 2.

…lassloaders

Fixes: spring-projects#4442

When the type mapper is initialized under one classloader and messages
are produced under another (e.g. Spring DevTools restart classloader),
the reverse lookup map keyed on `Class<?>` identity misses the entry
because two `Class<?>` objects representing the same class loaded by
different classloaders are not equal in a `HashMap` lookup. The fallback
writes the FQCN header instead of the configured alias, silently
breaking consumers that depend on the alias.

Fix by changing the reverse map key from `Class<?>` to `String`
(using `clazz.getName()`), which is classloader-agnostic.

The same change is applied to the deprecated `AbstractJavaTypeMapper` for Jackson 2.

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
@sobychacko

Copy link
Copy Markdown
Contributor Author

When back-porting to 3.3.x only jackson2 specific changes need to be cherry-picked as Jackson3 was only introduced in 4.0.x.

@artembilan artembilan merged commit e2a8cb3 into spring-projects:main Jun 1, 2026
3 checks passed
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.

Different behavior for value serializer mappings for different classloaders

2 participants