-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dependencies: migrate from json.net to
system.text.json
(#1274)
# Overview Migrate GCM from JSON.NET to `System.Text.Json`. The first commit updates to .NET 7.0 to take advantage of certain features like `JsonRequired`. The second updates `Microsoft.Identity.Client` so that the workaround for [this issue](AzureAD/microsoft-authentication-library-for-dotnet#4108 ) is no longer necessary. The third updates the current global Json.NET dependency to `System.Text.Json` and ensures it is only used for .NET Framework. The fourth adds a custom converter to handle Bitbucket's use of the non-standard 'scopes' property to provide token endpoint results. The fifth through ninth commits update `Trace2Message`, the Bitbucket REST API, the GitHub REST API, the Azure DevOps API tests, and OAuth-specific code to use `System.Text.Json` instead of Json.NET for JSON serialization/deserialization. # Performance comparison Comparison runs were done using [`dotnet-trace`](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-trace) with the command `printf "protocol=https\nhost=github.com" | git-credential-manager get`. The machine used was a Mac with a 2.4 GHz 8-Core Intel Core i9 processor running Ventura 13.4. Times are in milliseconds. ## Individual Run Times | **Newtonsoft.json** | **System.Text.Json** | |---------------------|----------------------| | 364.08 | 304.92 | | 366.11 | 305.23 | | 377.31 | 313.09 | | 381.3 | 313.51 | | 373.25 | 297.71 | | 373.98 | 312.78 | | 370.84 | 317.86 | | 368.25 | 311.78 | | 369.79 | 307.69 | ## Run Summary | | **Newtonsoft.json** | **System.Text.Json** | |-------------|---------------------|----------------------| | **Average** | 371.66 | 309.40 | | **Median** | 370.84 | 311.78 | ## Analysis Per the above, the transition to `System.Text.Json` and .NET 7.0 decreased end-to-end execution times by about 17% on average.
- Loading branch information
Showing
49 changed files
with
430 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/shared/Atlassian.Bitbucket.Tests/Atlassian.Bitbucket.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
src/shared/Atlassian.Bitbucket.Tests/BitbucketTokenEndpointResponseJsonTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Text.Json; | ||
using Xunit; | ||
|
||
namespace Atlassian.Bitbucket.Tests | ||
{ | ||
public class BitbucketTokenEndpointResponseJsonTest | ||
{ | ||
[Fact] | ||
public void BitbucketTokenEndpointResponseJson_Deserialize_Scopes_Not_Scope() | ||
public void BitbucketTokenEndpointResponseJson_Deserialize_Uses_Scopes() | ||
{ | ||
var scopesString = "a,b,c"; | ||
var json = "{access_token: '', token_type: '', scopes:'" + scopesString + "', scope: 'x,y,z'}"; | ||
var accessToken = "123"; | ||
var tokenType = "Bearer"; | ||
var expiresIn = 1000; | ||
var scopesString = "x,y,z"; | ||
var scopeString = "a,b,c"; | ||
|
||
var result = JsonConvert.DeserializeObject<BitbucketTokenEndpointResponseJson>(json); | ||
var json = $"{{\"access_token\": \"{accessToken}\", \"token_type\": \"{tokenType}\", \"expires_in\": {expiresIn}, \"scopes\": \"{scopesString}\", \"scope\": \"{scopeString}\"}}"; | ||
|
||
var result = JsonSerializer.Deserialize<BitbucketTokenEndpointResponseJson>(json, | ||
new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
Assert.Equal(accessToken, result.AccessToken); | ||
Assert.Equal(tokenType, result.TokenType); | ||
Assert.Equal(expiresIn, result.ExpiresIn); | ||
Assert.Equal(scopesString, result.Scope); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.