title: Extracting values from jwt token
body: <p>I am trying to create a new user and authenticate the user using JWT token. The token is getting created but when I try to extract values from the token, all the values are being returned as <code>null</code>. <code>jwtUtil.extractClaims()</code> is supposed to extract the values from the token but all values are null.</p>
  <pre class="lang-java prettyprint-override"><code>@GetMapping(&quot;/register/code/{token}&quot;)
  public HashMap&lt;String, Object&gt; register(@PathVariable(&quot;token&quot;) String token, HttpServletResponse httpServletResponse) {
     HashMap&lt;String, Object&gt; response = new HashMap&lt;&gt;();
     System.out.println(token);
      if (!jwtUtil.isTokenExpired(token)){
          System.out.println(&quot;User&quot;);
          User user = new User(
                  (String) jwtUtil.extractAllClaims(token).get(&quot;email&quot;),
                  (String) jwtUtil.extractAllClaims(token).get(&quot;phoneNumber&quot;),
                  (String) jwtUtil.extractAllClaims(token).get(&quot;ppUrl&quot;),
                  (String) jwtUtil.extractAllClaims(token).get(&quot;password&quot;)
          );
          System.out.println(&quot;User email &quot;+jwtUtil.extractAllClaims(token).get(&quot;email&quot;));
          String encodedPassword = passwordEncoder.encode(user.getPassword());
          // System.out.println(encodedPassword + &quot; THIS IS THE ENCODED PASSWORD&quot; +
          // authenticationRequest.getPassword());
          user.setPassword(encodedPassword);
          if (user.getProfilePicture() == null) {
              user.setProfilePicture(&quot;default.png&quot;);
          }
          User savedUser = userRepository.save(user);
          response.put(&quot;success&quot;, true);
          response.put(&quot;message&quot;, &quot;User Registered is Succesfull&quot;);
          System.out.println(&quot;mail verified&quot;);
          try {
              httpServletResponse.sendRedirect(&quot;/app&quot;);
          } catch (IOException e) {
              e.printStackTrace();
          }
          return response;
      } else {
          response.put(&quot;success&quot;, false);
          response.put(&quot;message&quot;, &quot;User Registered is not Succesfull!&quot;);
          return response;
      }
  }
  </code></pre>
  <p>The <code>extractClaims()</code> is as follows:</p>
  <pre class="lang-java prettyprint-override"><code>public Claims extractAllClaims(String token) {
      System.out.println(Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody());
      return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
  }
  </code></pre>
  <p>How else can I extract the values from the token.</p>
  <p>Edited to add the token generation code:</p>
  <pre class="lang-java prettyprint-override"><code>public String generateToken(User user) {
      Map&lt;String, Object&gt; claims = new HashMap&lt;&gt;();
      claims.put(&quot;user&quot;, user);
      return createToken(claims);
  }
  
  private String createToken(Map&lt;String, Object&gt; claims) {
      System.out.println(&quot;Claims inside createToken &quot;+claims);
      return Jwts.builder().setClaims(claims).setIssuedAt(new Date(System.currentTimeMillis()))
             .setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 10))
            .signWith(SignatureAlgorithm.HS256, secret).compact();
  }
  </code></pre>