Skip to content

Add regression test for require* claims with jjwt-gson - #1083

Open
kimseongchan0914 wants to merge 1 commit into
jwtk:mainfrom
kimseongchan0914:test/gson-require-claims-762
Open

kimseongchan0914 wants to merge 1 commit into
jwtk:mainfrom
kimseongchan0914:test/gson-require-claims-762

Conversation

@kimseongchan0914

Copy link
Copy Markdown

Fixes #762

Summary

#762 reported that the JwtParserBuilder require* methods failed when using jjwt-gson. Gson's default number handling deserialized every JSON number as a Double, so a claim like 42 came back as 42.0 and didn't match the expected value.

That root cause appears to have been fixed by #1009 (resolving #771). It configures GsonSerializer.DEFAULT_GSON, which GsonDeserializer also uses, with ToNumberPolicy.LONG_OR_DOUBLE. However, #762 is still open and there is no test covering this scenario end-to-end.

This PR adds Issue762Test, modeled on the reproducer from the issue. It builds a compressed JWS with GsonSerializer, parses it with GsonDeserializer, and asserts that all of the following succeed:

  • requireSubject, requireIssuer, requireAudience, requireId
  • requireExpiration, requireNotBefore, requireIssuedAt
  • require(...) with a String, an int and a long (Long.MAX_VALUE) claim

Testing

  • ./mvnw -pl impl test -Dtest=Issue762Test: passes.
  • With the deserializer temporarily switched to a plain new Gson() (the pre-Default Gson instance number strategy #1009 behavior), the test fails with IncorrectClaimException: Expected intClaim claim to be: 42, but was: 42.0., which confirms it catches the original bug.
  • ./mvnw -pl impl license:check: passes.

🤖 Generated with Claude Code

Gson's default number handling deserialized all JSON numbers as Double,
causing JwtParserBuilder require* assertions to fail (e.g. "Expected
intClaim claim to be: 42, but was: 42.0."). This was resolved by jwtk#1009,
which configures the default Gson instance with ToNumberPolicy.LONG_OR_DOUBLE.
This test guards against regressions.

Fixes jwtk#762

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

jjwt-gson cannot use the require series methods of io.jsonwebtoken.JwtParserBuilder normally

1 participant