-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support serialization for common scenarios #2268
Conversation
fix 2038 datetime issue
src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs
Outdated
Show resolved
Hide resolved
test/System.IdentityModel.Tokens.Jwt.Tests/JwtSecurityTokenTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTests.cs
Outdated
Show resolved
Hide resolved
} | ||
|
||
if (typeof(T) == typeof(object[])) | ||
return (T)(object)new object[] { obj }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are missing test coverage for these
src/Microsoft.IdentityModel.JsonWebTokens/Json/JsonWebToken.HeaderClaimSet.cs
Show resolved
Hide resolved
src/Microsoft.IdentityModel.JsonWebTokens/Json/JsonWebToken.PayloadClaimSet.cs
Show resolved
Hide resolved
src/Microsoft.IdentityModel.JsonWebTokens/Json/JsonWebToken.PayloadClaimSet.cs
Show resolved
Hide resolved
src/Microsoft.IdentityModel.JsonWebTokens/Json/JsonWebToken.PayloadClaimSet.cs
Show resolved
Hide resolved
|
||
return (T)(object)items; | ||
} | ||
else if (typeof(T) == typeof(long[])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have tests for these else ifs?
src/Microsoft.IdentityModel.Tokens/Json/JsonSerializerPrimitives.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Support serialization for common scenarios fix 2038 datetime issue * addressed some PR comments * missed a comma * removed some commented code * reorder to fix references --------- Co-authored-by: Brent Schmaltz <brentsch@hotmail.com>
* Support serialization for common scenarios fix 2038 datetime issue * addressed some PR comments * missed a comma * removed some commented code * reorder to fix references --------- Co-authored-by: Brent Schmaltz <brentsch@hotmail.com>
Added to the support 'T' that were available in 6x.
Fix 2038 datetime issue with JwtSecurityToken
If possible, Json will be mapped to one of the following types:
string[], List,,Collection, object[], List, Collection, int[], long[]
Dictionary<string, string>>, Dictionary<string, string[]>, Dictionary<string, List>, Dictionary<string, Collection>
Dictionary<string, object>, Dictionary<string, object[]>
With this change 7 will not be as general as 6x but will help with common scenarios.
A general solution will require a new api.
When calling TryGetPayloadValue the priority is generally:
sting, string[], List, Collection, ...
=================================
Pattern matching is applied when possible.
Json = {“p”:[1,2,3]}
TryGetPayLoadValue<string[]>(“p”) => string[]{“1”,”2”,”3”}
Json = {“p”:”value”}
TryGetPayLoadValue<string[]>(“p”) => string[]{“value”}
Json = {“p”:{”object”:”value”}}
TryGetPayLoadValue(“p”) => “{“object”:”value”}”
This will always return a value if it was the property exists.
=====================================
We still write obj.ToString() when serializing, even if we don't understand the type, as users that are working with Newtosoft.JObject will benefit. We are open to changing this depending on feedback.