Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

claims can't be parsed correctly #630

Closed
guofeiwu opened this issue Nov 20, 2020 · 2 comments
Closed

claims can't be parsed correctly #630

guofeiwu opened this issue Nov 20, 2020 · 2 comments

Comments

@guofeiwu
Copy link

image

I am used

Jwt parse = Jwts.parserBuilder()
            .setSigningKey(getKey())
            .build()
            .parse(token);
        Claims body = (Claims) parse.getBody();
      // will throw exception  
      Long id = body.get("id", Long.class));

like this
io.jsonwebtoken.RequiredTypeException: Cannot convert existing claim value of type 'class java.lang.Double' to desired type 'class java.lang.Long'. JJWT only converts simple String, Date, Long, Integer, Short and Byte types automatically. Anything more complex is expected to be already converted to your desired type by the JSON Deserializer implementation. You may specify a custom Deserializer for a JwtParser with the desired conversion configuration via the JwtParserBuilder.deserializeJsonWith() method.

I store the id is class is Long,the value is 100.0, I looked at the source code,if not type of Integer will not came in the if.

@guofeiwu
Copy link
Author

the jjwt version is 0.11.2

@guofeiwu guofeiwu changed the title Parse claims can't claims can't be parsed correctly Nov 20, 2020
@guofeiwu
Copy link
Author

ok I'm find the answer #616 thanks

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

No branches or pull requests

1 participant