Closed jonsagara closed 1 year ago
Hi @jonsagara , uhh, that's mostly question to System.Text.Json
, i personally don't know every single detail on how it works with different data types, but i'd try next things:
Try turn it to IDictionary
: public object addOn { get; set; } = null!;
-> public IDictionaty<string, object> addOn { get; set; } = null!;
Try using different json mapper (e.g. Newtonsoft.Json), see here: https://github.com/dvsekhvalnov/jose-jwt#customizing-json---object-parsing--mapping
After all you can avoid parsing your content to object model and simply string payload = JWT.Decode(...)
to get raw payload back and do whatever you want with it after.
I tried the three options, and the winner seems to be option 3:
JsonSerializer.Deserialize<T>
It worked when addOn
was both an object
and an IDictionary<string, object>
.
I updated my sample project with the workaround.
Thanks, @dvsekhvalnov !
I ran into an issue when trying to add a nested object to the payload where one of the nested object properties is a
System.Decimal
. Here are the models:If the
amount
property is a decimal value with no decimal places (e.g.,24m
), then I can successfully encode and decode the JWT. Here is example data that encodes and decodes properly:However, as soon as
amount
contains one or more decimal places (e.g.,24.00m
),JWT.Decode
throws an exception. Here is an example data that encodes successfully, but throws upon decoding:Here is the exception thrown by the
JWT.Decode
method:Are
System.Decimals
not supported by the underlying serializer? Is there a workaround for this?I have a full reproduction available here: https://github.com/jonsagara/JoseJwtReproduction
Thank you,
Jon