auth0 / java-jwt

Java implementation of JSON Web Token (JWT)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Claim asString returns null for types with valid string representations

worthc21 opened this issue · comments

Describe the problem

getClaim("X").asX returns null for values that have valid toString representations

When creating a private claim with an integer value -
withClaim("ID", 1234)
the decoded JWT
getClaim("ID").asString()
returns null

When creating a private claim with a boolean value -
withClaim("flag", true)
the decoded JWT
getClaim("flag").asString()
returns null

What was the expected behavior?

An integer value would return the string representation of the value (just as Integer.toString() does)
A boolean value would return the string representation of the value (just as Boolean.toString() does)

Versions

java-jwt: 4.0.0
java - JDK 11
spring boot - 2.7.4

Thanks for raising @worthc21. Yes, that is the expected behavior, as we first check that the node is textual. For the string value, you can use toString(). Hope that helps!

I updated the javadocs in #615 to be more accurate with the actual behavior. Thanks!

Nice - thanks for taking the time to address!