Skip to content

Respect Jackson type information for map values - #1074

Open
exijn wants to merge 2 commits into
jwtk:mainfrom
exijn:issue-1065-jackson-json-type-info
Open

exijn wants to merge 2 commits into
jwtk:mainfrom
exijn:issue-1065-jackson-json-type-info

Conversation

@exijn

@exijn exijn commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserve Jackson type metadata when serializing map values with JacksonSerializer.
  • Keep existing serialization behavior for ordinary values, including primitive arrays.

Root cause

JJWT supplies claims and headers to the serializer as Map<String, ?>. Jackson therefore sees each value as Object and does not apply type metadata configured on an interface or base type, so the @class property required by @JsonTypeInfo is omitted.

Changes

  • Serialize map values independently through the configured ObjectMapper, including nested maps, iterables, and object arrays.
  • Preserve Jackson's existing handling for primitive arrays.
  • Add an end-to-end regression test covering interface-based @JsonTypeInfo and custom deserialization.
  • Add coverage for ordinary byte[] and char[] map values.

Testing

  • ./mvnw -pl impl -am -Dtest=io.jsonwebtoken.CustomObjectDeserializationTest -Dsurefire.failIfNoSpecifiedTests=false test
  • ./mvnw -pl extensions/jackson -am test
  • ./mvnw -pl impl -am test
  • ./mvnw verify -Dgpg.skip=true

./mvnw license:check could not run in the linked worktree because the license plugin's Git check reported Bare Repository has neither a working tree, nor an index.

Coverage follow-up

  • Added testNestedMapValues for null map values, nested maps, iterables, and object arrays.
  • Focused JacksonSerializerTest: passed (14 tests).
  • Full clover:setup test reactor run on JDK 17: passed.
  • GitHub Actions code-coverage, license-check, and the complete JDK 8/11/17/21/25 matrix: passed.

Fixes #1065

@exijn

exijn commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

The code-coverage job failed because the recursive JacksonSerializer.toJsonNode path added by this PR had no coverage for null map values or non-primitive object arrays. Those two reachable cases left 6 statements and 4 conditional outcomes uncovered, resulting in 99.882120% total, 99.886835% statement, and 99.735099% conditional coverage.

I added testNestedMapValues, which verifies the serialized JSON for a null value, a nested map, an iterable, and a String[]. This follow-up changes tests only; production behavior is unchanged.

Verification:

  • Focused JacksonSerializerTest: passed (14 tests).
  • Full clover:setup test reactor run on JDK 17: passed.
  • JacksonSerializer Clover metrics: 100% methods, statements, and conditionals.
  • Aggregate local clover:check: blocked on Windows by the platform-specific test path leaving the unrelated existing PrivateECKey.getParams() method uncovered.
  • Local license:check: blocked in the linked worktree because the license plugin reported Bare Repository has neither a working tree, nor an index.
  • git diff --check: passed.
  • GitHub Actions: code-coverage, license-check, all 18 JDK 8/11/17/21/25 build jobs, and all Snyk checks passed.

Please review the added boundary-case coverage.

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.

JacksonSerializer does not respect JsonTypeInfo

1 participant