Parsing of complex claims

Issue #114 invalid
Thomas Stubbe created an issue

imagine the following token:

{
  "exp": 1520864017,
  "user_name": "admin",
  "scope": ["read","write","trust"],
  "authorities": ["ROLE_X", "ROLE_Y"],
  "jti": "someJti",
  "client_id": "someClient",
  "user": {
    "id": "1",
    "firstName": "admin",
    "moreValues": "...",
    "someEnumType": "someEnumValue",
    "someCollection": ["X", "Y", "Z"]
  }
}

Currently, I think there is no way to decently parse "user" with Jose4j.

  • Using JwtClaims.getClaim("user", UserClass.class) fails, because it can't handle the enum type (I guess).
  • JwtClaims.getStringClaimValue("user") fails as well because "The value of the 'user' claim is not the expected type" (it is already a hashMap)
  • JwtClaims.getClaim("user", Map.class) works, but the value of someCollection = a string, which isn't even valid JSON anymore, so you need to manually parse it.

getRawJson() is the only option, but that contains too much data to decently parse a UserClass object.

So, except if I'm missing something, this is currently not possible. It would be nice if one of the the three options where available:

  • getClaimValueAsJson(String)
  • parsing of sub-arrays / maps when using a map
  • decent JSON parsing for objects

Comments (2)

  1. Log in to comment