Skip to content

Commit b452a66

Browse files
swapped newtsonsoft json for system.text.json for consistent serialization.
1 parent 7beec7d commit b452a66

3 files changed

Lines changed: 17 additions & 43 deletions

File tree

hashicorp-vault-cagateway/Client/VaultHttp.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
using Keyfactor.Extensions.CAPlugin.HashicorpVault.APIProxy;
99
using Keyfactor.Logging;
1010
using Microsoft.Extensions.Logging;
11-
using Newtonsoft.Json;
1211
using RestSharp;
1312
using RestSharp.Serializers.Json;
1413
using System;
1514
using System.Collections.Generic;
1615
using System.Text.Json;
1716
using System.Text.Json.Serialization;
1817
using System.Threading.Tasks;
19-
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
2018

2119
namespace Keyfactor.Extensions.CAPlugin.HashicorpVault.Client
2220
{
@@ -38,8 +36,8 @@ public VaultHttp(string host, string mountPoint, string authToken, string nameSp
3836
_serializerOptions = new()
3937
{
4038
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
41-
RespectNullableAnnotations = true,
4239
PropertyNameCaseInsensitive = true,
40+
RespectNullableAnnotations = true,
4341
PreferredObjectCreationHandling = JsonObjectCreationHandling.Replace
4442
};
4543

@@ -71,7 +69,7 @@ public VaultHttp(string host, string mountPoint, string authToken, string nameSp
7169
public async Task<T> GetAsync<T>(string path, Dictionary<string, string> parameters = null)
7270
{
7371
logger.MethodEntry();
74-
logger.LogTrace($"preparing to send GET request to {path} with parameters {JsonConvert.SerializeObject(parameters)}");
72+
logger.LogTrace($"preparing to send GET request to {path} with parameters {JsonSerializer.Serialize(parameters)}");
7573

7674
try
7775
{
@@ -88,10 +86,11 @@ public async Task<T> GetAsync<T>(string path, Dictionary<string, string> paramet
8886
response.ThrowIfError();
8987
if (string.IsNullOrEmpty(response.Content)) throw new Exception(response.ErrorMessage ?? "no content returned from Vault");
9088

91-
logger.LogTrace($"deserializing the response into a {typeof(T)}");
92-
var deserialized = JsonConvert.DeserializeObject<T>(response.Content);
89+
logger.LogTrace($"deserializing the response into a {typeof(T)}");
90+
91+
var deserialized = JsonSerializer.Deserialize<T>(response.Content, _serializerOptions);
9392

94-
logger.LogTrace($"successfully deserialized the reponse");
93+
logger.LogTrace($"successfully deserialized the response");
9594

9695
return deserialized;
9796
}
@@ -120,7 +119,7 @@ public async Task<T> PostAsync<T>(string path, dynamic parameters = default)
120119
var request = new RestRequest(resourcePath, Method.Post);
121120
if (parameters != null)
122121
{
123-
string serializedParams = JsonConvert.SerializeObject(parameters);
122+
string serializedParams = JsonSerializer.Serialize(parameters);
124123
logger.LogTrace($"deserialized parameters (from {parameters.GetType()?.Name}): {serializedParams}");
125124
request.AddJsonBody(serializedParams);
126125
}
@@ -139,7 +138,7 @@ public async Task<T> PostAsync<T>(string path, dynamic parameters = default)
139138

140139
if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
141140
{
142-
errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(response.Content ?? "no content");
141+
errorResponse = JsonSerializer.Deserialize<ErrorResponse>(response.Content ?? "no content");
143142
string allErrors = "(Bad Request)";
144143
if (errorResponse?.Errors.Count > 0)
145144
{

hashicorp-vault-cagateway/Properties/launchSettings.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

hashicorp-vault-cagateway/hashicorp-vault-caplugin.csproj

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,20 @@
3333
</ItemGroup>
3434

3535
<ItemGroup>
36-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0" />
37-
<PackageReference Include="Keyfactor.AnyGateway.IAnyCAPlugin" Version="3.0.0" />
38-
<PackageReference Include="Keyfactor.Logging" Version="1.1.2" />
39-
<PackageReference Include="Keyfactor.PKI" Version="5.5.0" />
40-
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
41-
<PackageReference Include="RestSharp" Version="112.1.0" />
42-
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
43-
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="9.0.0" />
44-
<PackageReference Include="System.Text.Json" Version="9.0.0" />
36+
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
37+
<PackageReference Include="Keyfactor.AnyGateway.IAnyCAPlugin" Version="3.1.0" />
38+
<PackageReference Include="Keyfactor.Logging" Version="1.3.0" />
39+
<PackageReference Include="Keyfactor.PKI" Version="8.1.1" />
40+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
41+
<PackageReference Include="RestSharp" Version="113.0.0" />
42+
<PackageReference Include="System.Formats.Asn1" Version="10.0.0" />
43+
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="10.0.0" />
44+
<PackageReference Include="System.Text.Json" Version="10.0.0" />
4545
</ItemGroup>
4646

4747
<ItemGroup>
4848
<Content Include="Connectors\manifest.json">
4949
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5050
</Content>
5151
</ItemGroup>
52-
53-
<ItemGroup>
54-
<Compile Update="Properties\Resources.Designer.cs">
55-
<DesignTime>True</DesignTime>
56-
<AutoGen>True</AutoGen>
57-
<DependentUpon>Resources.resx</DependentUpon>
58-
</Compile>
59-
</ItemGroup>
60-
61-
<ItemGroup>
62-
<EmbeddedResource Update="Properties\Resources.resx">
63-
<Generator>ResXFileCodeGenerator</Generator>
64-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
65-
</EmbeddedResource>
66-
</ItemGroup>
6752
</Project>

0 commit comments

Comments
 (0)