In JWT libraries for Java, the Claims interface represents the payload of a token: the set of name-value pairs such as sub, exp and any custom data. In JJWT (io.jsonwebtoken.Claims) it extends Map<String, Object> and adds typed getters, so after verifying a token you read the subject, expiry and custom values through it.
This article uses the JJWT 0.12+ API, where several older methods are deprecated or removed.
A JWT has three parts: header, payload and signature. The payload holds the claims. They fall into three groups:
| Type | Examples | Notes |
|---|---|---|
| Registered | iss, sub, aud, exp, nbf, iat, jti | Defined by RFC 7519 |
| Public | email, name | Names should be collision-resistant or registered |
| Private | tenantId, roles | Agreed between your own services |
The payload is only Base64URL-encoded, not encrypted. Anyone holding the token can read the claims, so never place passwords or other secrets in them. The signature only proves the content was not altered.
Claims gives you a typed view of the payload:
| Method | Returns | Claim |
|---|---|---|
getIssuer() | String | iss |
getSubject() | String | sub |
getAudience() | Set<String> | aud |
getExpiration() | Date | exp |
getNotBefore() | Date | nbf |
getIssuedAt() | Date | iat |
getId() | String | jti |
get(name, Class) | T | any custom claim, converted to the type |
Because it is a Map, you can also call containsKey, keySet and get("roles"). Parsed claims are read-only. To produce claims you use the builder (Jwts.builder()), not by mutating a Claims object.
signWith(key) picks a suitable HMAC algorithm from the key size. Load the secret from configuration or a secret store, never from source code. To create a random key for tests, use Jwts.SIG.HS256.key().build().
parseSignedClaims verifies the signature before returning, and throws if the token is unsigned or tampered. The older parseClaimsJws and setSigningKey methods are deprecated since 0.12, so avoid them in new code. Exceptions you will meet include ExpiredJwtException, MalformedJwtException, SignatureException and the common parent JwtException. Expiry is checked automatically during parsing; you do not compare getExpiration() yourself.
Spring Security has its own claims model. With spring-boot-starter-oauth2-resource-server, a decoded token is an org.springframework.security.oauth2.jwt.Jwt, and jwt.getClaims() returns a Map<String, Object>, while jwt.getSubject() and jwt.getClaimAsStringList("roles") give typed access. Map claims to authorities with a JwtAuthenticationConverter. For most applications that validate tokens from an identity provider, the resource server support is preferable to hand-written JJWT parsing.
aud when several services share an issuer.No. The standard defines the claims. Claims is the JJWT library's Java type for them, and other libraries have their own.
Call claims.get("tenantId", String.class). It returns null if the claim is absent.
No. A signature covers the payload, so any change invalidates it. Issue a new token.
It was deprecated and replaced in JJWT 0.12. Use verifyWith(key) and parseSignedClaims.
The Claims interface is JJWT's typed, read-only view of a verified token payload, with getters for registered claims and get(name, type) for custom ones. Build tokens with Jwts.builder(), parse them with Jwts.parser().verifyWith(key), keep secrets out of the payload and prefer Spring Security's resource server when validating tokens from an identity provider.