I’m new to Java and have been tasked with updating dependencies in our pom.xml. We’re moving io.jsonwebtoken
from 0.10.1
to 0.12.5
which has caused one of our custom util methods to fail. Here’s the original method:
public static Jws<Claims> verifyToken(String token, Key key) throws Exception {
return Jwts.parser().setSigningKey(key).parseClaimsJws(token);
}
VS Code has highlighted two issues with the return statement:
- The
setSigningKey
is deprecated - The method
parseClaimsJws(String)
is undefined for the type JwtParserBuilder
After spending some time trying to track down a fix, I settled on the following update:
return Jwts.parser().setSigningKey(key).build().parseSignedClaims(token).getPayload();
The setSigningKey
method is still in use, but functional. The getPayload
method is returning Claims io.jsonwebtoken.Jwt.getPayload()
. However, now the entire line is highlighted with the error: Type mismatch: cannot convert from Claims to Jws<Claims>
As I mentioned, I’m still new to Java, so I’m unsure how to shoehorn a Claims
object into a Jws<Claims>
object.
We’re on Java 17.