0

I have used the brilliant JSONAware interface (with the method toJSONString) on jose4j so that I can add a complex JSON structure under a single claim - it generates just what I wanted the JWT to look like.

However now I'm trying to extract the same claim from the JWT, and there seems no built in way to reverse it. I was hoping for another interface (or a method on the same interface) with a method called fromJSONString or something that I could call with:

getClaimValue(String, JSONAwareImpl.class)

that then returned the class (my using the implementation of the method).

Any ideas on this? At the moment my only solution is to get the entire JWT in raw format and parse the entire thing to extract just my claim. It just seemed a little strange to be able to go one way and not back the other way, and wondered if I have just missed something?

Thanks.

Rob
  • 35
  • 1
  • 6
  • Not really missing anything. The JSON functionality was derived from json-simple and the parsing is intentionally pretty simplistic in that it converts JSON to an object tree of basic java types like String, number, boolean, Map and List. You could traverse that tree for your claim and build your object for it (to avoid parsing the raw JWT JSON payload again). – Brian Campbell May 19 '18 at 14:39
  • Thank Brian for the clarification. I did have a quick look at the code and couldn't see a good way of adding the suggested method - it would seem to require reconstructing the JSon from the Map and then passing it to the interface implementation that would then use it's own parser to process the JSon. (Which just seemed like too many JSon -> structure -> Json -> Structure transitions) – Rob May 21 '18 at 07:10

0 Answers0