You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have noticed that the package github.com/golang-jwt/jwt/v5 has a global config flag MarshalSingleStringAsArray. This was previously discussed in #277, which was closed as fixed by #278. However, #278 did not actually remove the MarshalSingleStringAsArray as far as I can tell. It seems like folks were in agreement at the time that having global mutable state at the package level was not preferred.
Imagine a program that needs to use this library with different settings in different areas of the program
In fact, I am writing such a program.
I did spend a little time thinking on how this could be accomplished. This is in fact a somewhat tricky problem, because the custom MarshalJSON function has no way to directly receive extra parameters. I think however that the type system could be used to encode this information. I have created a simple proof of concept for how this could work which you can see on the Go Playground here, and which I have reproduced below for posterity:
I think the biggest problem I see is that this will break compatibility for existing API users. Perhaps there might be a way to make the existing ClaimStrings type implement the interface (which would then need to be named something different -- also how would SetClaims() work? maybe it would need to be immutable).
The text was updated successfully, but these errors were encountered:
I have noticed that the package
github.com/golang-jwt/jwt/v5
has a global config flagMarshalSingleStringAsArray
. This was previously discussed in #277, which was closed as fixed by #278. However, #278 did not actually remove theMarshalSingleStringAsArray
as far as I can tell. It seems like folks were in agreement at the time that having global mutable state at the package level was not preferred.In fact, I am writing such a program.
I did spend a little time thinking on how this could be accomplished. This is in fact a somewhat tricky problem, because the custom MarshalJSON function has no way to directly receive extra parameters. I think however that the type system could be used to encode this information. I have created a simple proof of concept for how this could work which you can see on the Go Playground here, and which I have reproduced below for posterity:
I think the biggest problem I see is that this will break compatibility for existing API users. Perhaps there might be a way to make the existing
ClaimStrings
type implement the interface (which would then need to be named something different -- also how wouldSetClaims()
work? maybe it would need to be immutable).The text was updated successfully, but these errors were encountered: