Update value for an existing Claim #1039
Answered
by
lhazlewood
mparthasarathi
asked this question in
Q&A
|
I am trying to upgrade to latest version(0.13.0) and stuck at a point. Our code base has got functionality where it is trying to update an existing Claim(as per the current flow). But with the latest version, I am getting Claims existingClaims = getExistingClaims()
String existingClaimName = "some_name";
boolean claimValue = true;
existingClaims.put(existingClaimName, claimValue ); // with latest version exception thrown |
Answered by
lhazlewood
Jan 28, 2026
Replies: 1 comment 1 reply
|
Hi there! Claims are indeed immutable, so if you need to modify an instance for continued re-use later, you'll need to create a new instance based on the previous one. Example: Claims newClaims = Jwts.claims().add(existingClaims).add(existingClaimName, claimValue).build();but if you only need to override a few claims for a single JWT, and you don't need a Jwts.builder().claims(existingClaims).claim(existingClaimName, claimValue)... // etc... |
1 reply
Answer selected by
mparthasarathi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there!
Claims are indeed immutable, so if you need to modify an instance for continued re-use later, you'll need to create a new instance based on the previous one. Example:
but if you only need to override a few claims for a single JWT, and you don't need a
newClaimsinstance for continued use, you can do it inline when creating the JWT instead: