title: Generate token in rest java api
body: <p>I have a Java Restful api (I use JAX-RS) and I need to create a post method that returns a token.</p>
  
  <p>However my method is giving exception in the method 'gerarToken'</p>
  
  <p>Can anybody help me?
  Follow below code</p>
  
  <pre><code>@POST
  @Path("/login")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response fazerLogin(String credenciais) {
      try {
          Gson gson = new Gson();
          UsuarioTO u = gson.fromJson(credenciais, UsuarioTO.class);
          validarCrendenciais(u);
          String token = gerarToken(u.getLogin(), 1);
          return Response.ok(token).build();
      } catch (Exception e) {
          e.printStackTrace();
          return Response.status(Response.Status.UNAUTHORIZED).build();
      }
  }
  
  private String gerarToken(String login,Integer expiraEmDias ){
      SignatureAlgorithm algoritimoAssinatura = SignatureAlgorithm.HS512;
      Date agora = new Date();
      Calendar expira = Calendar.getInstance();
      expira.add(Calendar.DAY_OF_MONTH, expiraEmDias);
      byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary("E5c0l4r");
      SecretKeySpec key = new SecretKeySpec(apiKeySecretBytes, algoritimoAssinatura.getJcaName());
      JwtBuilder construtor = Jwts.builder()
                                  .setIssuedAt(agora)
                                  .setSubject(login)
                                  .setIssuer(login)
                                  .setWith(algoritimoAssinatura,key)   
                                  .setExpiration(expira.getTime());
  
      return construtor.compact();
  
  }
  </code></pre>
  
  <p>In 'Jwts.builder' throw that exception
      The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
      java.lang.NoSuchFieldError: USE_DEFAULTS
      at com.fasterxml.jackson.annotation.JsonInclude$Value.(JsonInclude.java:204)
      at com.fasterxml.jackson.databind.cfg.MapperConfig.(MapperConfig.java:44)
      at com.fasterxml.jackson.databind.ObjectMapper.(ObjectMapper.java:549)
      at com.fasterxml.jackson.databind.ObjectMapper.(ObjectMapper.java:465)
      at io.jsonwebtoken.impl.DefaultJwtBuilder.(DefaultJwtBuilder.java:42)
      at io.jsonwebtoken.Jwts.builder(Jwts.java:116)
      at br.gov.es.dataci.aprender.controleacesso.ControleAcesso.gerarToken(ControleAcesso.java:85)
      at br.gov.es.dataci.aprender.controleacesso.ControleAcesso.fazerLogin(ControleAcesso.java:46)</p>