jjwt icon indicating copy to clipboard operation
jjwt copied to clipboard

JwtParser to parse CharSequence instead of String?

Open zolyfarkas opened this issue 6 years ago • 5 comments

JwtParser parameters that get parsed are all String, can these be made to CharSequence? it would make this a bit more flexible...

zolyfarkas avatar Jun 13 '18 14:06 zolyfarkas

I am not sure I agree with having CharSequence type parameters in the public interfaces without a strong justification.

My main concern here is that implementations of CharSequence are not guaranteed to be immutable, while String is.

azagniotov avatar Jun 30 '18 03:06 azagniotov

I don't understand the request exactly - can you show a code snippet example of what you're asking for?

lhazlewood avatar Jul 23 '18 16:07 lhazlewood

Closing due to inactivity or follow up from OP.

lhazlewood avatar Mar 10 '19 17:03 lhazlewood

well somehow I missed the notifications for the followup questions... this awesome email spam filters in action...

the idea is when parsing from some source CharSequence is a bit more flexible... (String, StringBuilder ...)

for an example, in class Integer you have both:

public static int parseUnsignedInt(String s, int radix)

and: public static int parseUnsignedInt(CharSequence s, int beginIndex, int endIndex, int radix)

in case on JWT, lets say the web token needs to be parsed out of a string like:

"Bearer [JWT token]"

I want tp avoid doing a substring() and allocate memory for no good reason.. having a CharSequence parsing variant I could simply do: parse(myString, "Bearer ".length(), myString.length())

The existing interfaces don't need to be changed....

zolyfarkas avatar Mar 11 '19 00:03 zolyfarkas

Reopening, but I don't know when we'll get to it. This is low priority given the 1.0 feature set we need to support.

lhazlewood avatar Mar 24 '19 17:03 lhazlewood

The IO Streams work commited via https://github.com/jwtk/jjwt/commit/b687ca5c72681a41449fcb252549559e4e06771f makes this much easier, so we can sneak it in for 0.12.0. I should have a PR shortly.

lhazlewood avatar Sep 30 '23 03:09 lhazlewood