-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from Newtonsoft to System.Text.Json (#91)
Co-authored-by: MD Ashique <noorani.ashique5@gmail.com> Signed-off-by: Shubham Sharma <shubhash@microsoft.com> This PR updates the codebase to use STJ (System.Text.Json) instead of Newtonsoft. There are a few updates - Instead of JToken, all internal classes use JsonElement (STJ) for storing data, along with a custom JsonElementConverter that converts with UnsafeRelaxedJsonEscaping. - The APIs support both STJ and NS as method parameters - this is because the underlying functions framework does not support expressions using STJ - The method return type and all internals are STJ based only - Update CloudEvents to 2.6.0 - Add Generic Converter base class for converting JsonElement to T types - Add new tests
- Loading branch information
1 parent
a2a5696
commit 1f8e283
Showing
71 changed files
with
884 additions
and
414 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
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
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
50 changes: 50 additions & 0 deletions
50
src/Microsoft.Azure.WebJobs.Extensions.Dapr/Bindings/Converters/DaprGenericsConverterBase.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
// ------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Dapr.Bindings.Converters | ||
{ | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Dapr.Services; | ||
|
||
/// <summary> | ||
/// A base class for generic converters. | ||
/// </summary> | ||
/// <typeparam name="T1">Type of the input data.</typeparam> | ||
/// <typeparam name="T2">Type of the output data after conversion.</typeparam> | ||
internal abstract class DaprGenericsConverterBase<T1, T2> : IAsyncConverter<T1, T2> | ||
{ | ||
readonly DaprServiceClient daprClient; | ||
|
||
public DaprGenericsConverterBase(DaprServiceClient daprClient) | ||
{ | ||
this.daprClient = daprClient; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the string representation of the input data of type T1. | ||
/// </summary> | ||
/// <param name="input">The input data to be serialized.</param> | ||
/// <param name="cancellationToken">Cancellation token.</param> | ||
public abstract Task<string> GetStringContentAsync(T1 input, CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// Converts the input data of type T1 to the output data of type T2. | ||
/// </summary> | ||
/// <param name="input">The input data to be converted.</param> | ||
/// <param name="cancellationToken">Cancellation token.</param> | ||
async Task<T2> IAsyncConverter<T1, T2>.ConvertAsync( | ||
T1 input, | ||
CancellationToken cancellationToken) | ||
{ | ||
string result = await this.GetStringContentAsync(input, cancellationToken); | ||
return JsonSerializer.Deserialize<T2>(result) | ||
?? throw new InvalidDataException("Unable to deserialize the secret."); | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...crosoft.Azure.WebJobs.Extensions.Dapr/Bindings/Converters/DaprSecretsGenericsConverter.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
// ------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.Dapr.Bindings.Converters | ||
{ | ||
using System.Text.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Extensions.Dapr.Services; | ||
using Microsoft.Azure.WebJobs.Extensions.Dapr.Utils; | ||
|
||
internal class DaprSecretsGenericsConverter<T> : DaprGenericsConverterBase<DaprSecretAttribute, T> | ||
{ | ||
readonly DaprServiceClient daprClient; | ||
|
||
public DaprSecretsGenericsConverter(DaprServiceClient daprClient) | ||
: base(daprClient) | ||
{ | ||
this.daprClient = daprClient; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the string representation of DaprSecretAttribute. | ||
/// </summary> | ||
/// <param name="input">The DaprSecretAttribute to be serialized.</param> | ||
/// <param name="cancellationToken">Cancellation token.</param> | ||
public async override Task<string> GetStringContentAsync(DaprSecretAttribute input, CancellationToken cancellationToken) | ||
{ | ||
var secret = await this.daprClient.GetSecretAsync( | ||
input.DaprAddress, | ||
input.SecretStoreName, | ||
input.Key, | ||
input.Metadata, | ||
cancellationToken); | ||
return JsonSerializer.Serialize(secret, JsonUtils.DefaultSerializerOptions); | ||
} | ||
} | ||
} |
Oops, something went wrong.