Skip to content

Conversation

@cowtowncoder
Copy link
Member

Summary

This PR adds a failing test that reproduces issue #5285, where wildcard generic types (e.g., MessageWrapper<?>) incorrectly resolve to Object instead of respecting the type parameter's bound.

Problem Demonstrated

When processing a field declared with a wildcard generic type like MessageWrapper<?> where MessageWrapper<T extends Settings>, Jackson's type resolution:

  1. Incorrectly resolves the wildcard to java.lang.Object
  2. Should resolve to the type parameter's bound (Settings)

This causes polymorphic type information to be lost during serialization when @JsonTypeInfo annotations are used.

Test Details

The test compares serialization of identical object instances using two different field declarations:

  • MessageWrapper<?> wildcardWrapper (fails - missing "type" field)
  • MessageWrapper<EmailSettings> specificWrapper (works - includes "type":"EMAIL")

Expected vs Actual

Wildcard (Current - Broken):

Type: MessageWrapper<java.lang.Object>
JSON: {"settings":{"email":"me@me.com"},"message":"Sample Message"}

Specific Type (Works):

Type: MessageWrapper<EmailSettings>
JSON: {"settings":{"type":"EMAIL","email":"me@me.com"},"message":"Sample Message"}

The wildcard case should also include the "type":"EMAIL" field for polymorphic serialization.

Related Issue

Fixes #5285

🤖 Generated with Claude Code

This test demonstrates the issue where wildcard generic types
(e.g., MessageWrapper<?>) incorrectly resolve to Object instead
of respecting the type parameter's bound (e.g., Settings).

This causes polymorphic type information to be lost during
serialization when @JsonTypeInfo annotations are used.

Related to #5285

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@cowtowncoder cowtowncoder added 2.21 gen-ai PR created with Generative AI (whole or assisted) (or issue for which gen-ai seems suitable) labels Oct 26, 2025
@cowtowncoder cowtowncoder self-assigned this Oct 26, 2025
@cowtowncoder cowtowncoder marked this pull request as draft October 26, 2025 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.21 gen-ai PR created with Generative AI (whole or assisted) (or issue for which gen-ai seems suitable)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants