88using Keyfactor . Extensions . CAPlugin . HashicorpVault . APIProxy ;
99using Keyfactor . Logging ;
1010using Microsoft . Extensions . Logging ;
11- using Newtonsoft . Json ;
1211using RestSharp ;
1312using RestSharp . Serializers . Json ;
1413using System ;
1514using System . Collections . Generic ;
1615using System . Text . Json ;
1716using System . Text . Json . Serialization ;
1817using System . Threading . Tasks ;
19- using JsonSerializer = Newtonsoft . Json . JsonSerializer ;
2018
2119namespace 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 {
0 commit comments