Update value for an existing Claim #1039
-
|
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 |
Beta Was this translation helpful? Give feedback.
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... |
Beta Was this translation helpful? Give feedback.
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: