'setClaims(java.util.Map<java.lang.String,?>)' is deprecated

199 views Asked by At

This is my example code:

    private String createToken(Map<String,Object> claims, String subject) {
        return Jwts.builder()
                .setClaims(claims)
                .setSubject(subject)
                .setIssuedAt(new Date(System.currentTimeMillis()))
                //the token will be expired in 10 hours
                .setExpiration(new Date(System.currentTimeMillis() + 1000* 60 * 60 *10))
                .signWith(SignatureAlgorithm.HS256, secret).compact();
    }

setClaims setSubject setIssuedAt setExpiration signWith are all deprecated

I need to use JWT in API, and the IDE tells me that the .signXXX method are deprecated, maybe it's because my dependency version is latest, my version is 0.12.5

1

There are 1 answers

1
Salim Jabbour On

Just remove the set from every method. and for the signWith() method, modify it the way I did note: see the picture below.

enter image description here