jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Add failing test for wildcard generic type resolution (#5285)

Open cowtowncoder opened this issue 1 month ago • 0 comments

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":"[email protected]"},"message":"Sample Message"}

Specific Type (Works):

Type: MessageWrapper<EmailSettings>
JSON: {"settings":{"type":"EMAIL","email":"[email protected]"},"message":"Sample Message"}

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

Related Issue

Fixes #5285

🤖 Generated with Claude Code

cowtowncoder avatar Oct 26 '25 23:10 cowtowncoder