JJWT 0.12 marks setClaims, setSubject and signWith(SignatureAlgorithm) as deprecated when you build a token
Fix it fast
Most common cause, 1 of 4setClaims or addClaims still fills the payload
Use claims(Map), which adds the pairs and overwrites only names that already exist.
// add a map to whatever is already set
String jws = Jwts.builder()
.subject(userId)
.claims(extraClaims)
.signWith(key)
.compact();
// replace everything set so far, as the old setClaims did
String replaced = Jwts.builder()
.claims().empty().add(extraClaims).and()
.signWith(key)
.compact();Short answer
In JJWT 0.12 and later, JwtBuilder.setClaims(Map) is deprecated in favour of claims(Map) or the claims() builder, and setSubject, setExpiration and signWith(SignatureAlgorithm, key) went the same way. setClaims replaced the whole payload while claims(Map) adds to it. Rename the calls to subject(), expiration(), issuedAt(), sign with signWith(key) or Jwts.SIG, and build standalone claims with Jwts.claims().build().
Which cause do you have?
List every token-building call that 0.12 changed. Each pattern in the search belongs to one cause below, so the matches show which edits the code needs.
grep -rnE "setClaims\(|addClaims\(|\.set(Subject|Issuer|Audience|Expiration|NotBefore|IssuedAt|Id)\(|signWith\(SignatureAlgorithm|SignatureAlgorithm\.|Jwts\.claims\(\)" src/Then find the line you see in this list and open its fix:
- 1setClaims or addClaims still fills the payload
Matches for setClaims( or addClaims(, and sometimes a token that lacks a claim you set a line earlier - 2The standard claim setters use the old set prefix
Warnings point at setSubject, setIssuer, setExpiration or setIssuedAt rather than setClaims - 3signWith still takes the SignatureAlgorithm enum
Matches for signWith(SignatureAlgorithm.HS256, ...) or signWith(key, SignatureAlgorithm.RS256) - 4Jwts.claims() now returns a builder, not a Claims object
A compile error on a line such as Claims claims = Jwts.claims(); after the upgrade, not just a warning
What does the error look like?
jjwt: setClaims(java.util.Map) is deprecatedDeprecation warnings on setSubject, setExpiration and signWith(SignatureAlgorithm, ...) after moving to JJWT 0.12The token built with setClaims has no sub claim even though setSubject was called
Cause 1 of 4
setClaims or addClaims still fills the payload
You seeMatches for setClaims( or addClaims(, and sometimes a token that lacks a claim you set a line earlier
Check
JwtBuilder.setClaims(Map) is deprecated since 0.12.0, and its Javadoc describes it as a replace: it empties the claims and then adds the map. Code that called setSubject before setClaims therefore lost the subject. addClaims is deprecated too and will be removed before 1.0.
Fix
Use claims(Map), which adds the pairs and overwrites only names that already exist. When you really mean to wipe earlier claims, say so with the nested builder.
// add a map to whatever is already set
String jws = Jwts.builder()
.subject(userId)
.claims(extraClaims)
.signWith(key)
.compact();
// replace everything set so far, as the old setClaims did
String replaced = Jwts.builder()
.claims().empty().add(extraClaims).and()
.signWith(key)
.compact();Verify
Decode the new token's payload and confirm sub and every custom claim are present, and recompile with no deprecation warning for setClaims.
./mvnw -q compileConfirmed by raw.githubusercontent.com
Cause 2 of 4
The standard claim setters use the old set prefix
You seeWarnings point at setSubject, setIssuer, setExpiration or setIssuedAt rather than setClaims
Check
ClaimsMutator, which JwtBuilder implements, deprecates each setter since 0.12.0 in favour of a shorter builder-style name. setAudience is replaced by the audience() collection because aud may hold several values.
Fix
Drop the set prefix. For the audience, add values through the nested collection and return to the builder with and().
String jws = Jwts.builder()
.issuer("https://auth.example.com")
.subject(userId)
.audience().add("orders-api").and()
.issuedAt(now)
.expiration(new Date(now.getTime() + 15 * 60 * 1000))
.signWith(key)
.compact();Verify
The build compiles cleanly and the decoded payload holds iss, sub, aud, iat and exp with the values you passed.
Confirmed by raw.githubusercontent.com
Cause 3 of 4
signWith still takes the SignatureAlgorithm enum
You seeMatches for signWith(SignatureAlgorithm.HS256, ...) or signWith(key, SignatureAlgorithm.RS256)
Check
The changelog for 0.12.0 deprecates the io.jsonwebtoken.SignatureAlgorithm enum in favour of the Jwts.SIG registry, and JwtBuilder deprecates every signWith overload that accepts the enum. Keys.secretKeyFor, which also takes the enum, is deprecated with it.
Fix
Call signWith(key), which picks the algorithm from the key's type and length, or name one through Jwts.SIG. Generate new HMAC keys from the algorithm itself.
SecretKey key = Jwts.SIG.HS256.key().build();
String jws = Jwts.builder().subject(userId).signWith(key, Jwts.SIG.HS256).compact();Verify
No warning mentions SignatureAlgorithm, and the token header still shows the alg your verifiers expect.
Confirmed by raw.githubusercontent.com
Cause 4 of 4
Jwts.claims() now returns a builder, not a Claims object
You seeA compile error on a line such as Claims claims = Jwts.claims(); after the upgrade, not just a warning
Check
Claims and Header objects became immutable in 0.12.0. The changelog lists, among the breaking changes, that Jwts.claims() returns a ClaimsBuilder instead of a Claims instance, so code that created an empty Claims and filled it no longer compiles.
Fix
Finish the builder with build(), or skip the separate object and pass the values straight to the JwtBuilder.
Claims claims = Jwts.claims()
.subject(userId)
.add("role", "admin")
.build();Verify
The class compiles and the token carries the claims taken from the built object.
./mvnw -q testConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Compile with deprecation warnings visible and treat new ones in the security package as a task, because JJWT says some of them will go before 1.0.
- Keep a unit test that builds a token and asserts each expected claim, which catches the replace-versus-add change straight away.
- Move jjwt-api, jjwt-impl and the JSON module together through one version property.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.