arun11299 / cpp-jwt

JSON Web Token library for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Numbers not support in payload

lzy1g1225 opened this issue · comments

Hi, I tried modify the basic sample code from
" jwt::jwt_object obj{algorithm("HS256"), payload({{"some", "payload"}}), secret(key)}; "
to
" jwt::jwt_object obj{algorithm("HS256"), payload({{"some", 123}}), secret(key)}; "
and getting compilation error
"Severity Code Description Project File Line Suppression State
Error C2664 'jwt::params::detail::payload_param<std::unordered_map<std::string,std::string,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>> jwt::params::payload(const jwt::params::param_init_list_t &)': cannot convert argument 1 from 'initializer list' to 'const jwt::params::param_init_list_t &' "
my IDE is vs2017 and compiler version is 19.15.

After checking documentation I noticed the payload cannot be initialized by parameters other than string and string_view, for this reason I have to convert my parameter from numbers to string, I think this could impact the performance, could you improve that?

Hi @lzy1g1225
Agree that it is an inconvenience. But, you can always use "add_payload" method to add an integer.

The payload you pass in the constructor is supposed to be homogenous i.e all payload values should have same key and value type. I think I can use some template magic to achieve that instead of always limiting it to string types.

Let me know if "add_payload" method is good enough for the time being.

@lzy1g1225 I am closing this issue for now as there is an alternative API available using which you wouldn't need to convert number to a string. I understand that it is bit more verbose, but that's what we have now :D.
Please do reopen if you think otherwise.

Thank You.