From 8adebea92912403db08627554d08043afa2e4534 Mon Sep 17 00:00:00 2001 From: Jkorf Date: Wed, 28 Apr 2021 13:13:48 +0200 Subject: [PATCH] Added options to pass a JsonSerializer to the SendRequest method to use for deserialization --- CryptoExchange.Net/CryptoExchange.Net.xml | 7 +++++-- CryptoExchange.Net/RestClient.cs | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CryptoExchange.Net/CryptoExchange.Net.xml b/CryptoExchange.Net/CryptoExchange.Net.xml index 32ebd8e..0bb5baf 100644 --- a/CryptoExchange.Net/CryptoExchange.Net.xml +++ b/CryptoExchange.Net/CryptoExchange.Net.xml @@ -2771,7 +2771,7 @@ The roundtrip time of the ping request - + Execute a request @@ -2784,13 +2784,16 @@ Whether or not the resulting object should be checked for missing properties in the mapping (only outputs if log verbosity is Debug) Where the post parameters should be placed How array parameters should be serialized + Credits used for the request + The JsonSerializer to use for deserialization - + Executes the request and returns the string result The request object to execute + The JsonSerializer to use for deserialization Cancellation token diff --git a/CryptoExchange.Net/RestClient.cs b/CryptoExchange.Net/RestClient.cs index aca85af..5d44df4 100644 --- a/CryptoExchange.Net/RestClient.cs +++ b/CryptoExchange.Net/RestClient.cs @@ -169,10 +169,14 @@ namespace CryptoExchange.Net /// Whether or not the resulting object should be checked for missing properties in the mapping (only outputs if log verbosity is Debug) /// Where the post parameters should be placed /// How array parameters should be serialized + /// Credits used for the request + /// The JsonSerializer to use for deserialization /// [return: NotNull] protected virtual async Task> SendRequest(Uri uri, HttpMethod method, CancellationToken cancellationToken, - Dictionary? parameters = null, bool signed = false, bool checkResult = true, PostParameters? postPosition = null, ArrayParametersSerialization? arraySerialization = null, int credits=1) where T : class + Dictionary? parameters = null, bool signed = false, bool checkResult = true, + PostParameters? postPosition = null, ArrayParametersSerialization? arraySerialization = null, int credits = 1, + JsonSerializer? deserializer = null) where T : class { var requestId = NextId(); log.Write(LogVerbosity.Debug, $"[{requestId}] Creating request for " + uri); @@ -201,16 +205,17 @@ namespace CryptoExchange.Net paramString = " with request body " + request.Content; log.Write(LogVerbosity.Debug, $"[{requestId}] Sending {method}{(signed ? " signed" : "")} request to {request.Uri}{paramString ?? " "}{(apiProxy == null ? "" : $" via proxy {apiProxy.Host}")}"); - return await GetResponse(request, cancellationToken).ConfigureAwait(false); + return await GetResponse(request, deserializer, cancellationToken).ConfigureAwait(false); } /// /// Executes the request and returns the string result /// /// The request object to execute + /// The JsonSerializer to use for deserialization /// Cancellation token /// - protected virtual async Task> GetResponse(IRequest request, CancellationToken cancellationToken) + protected virtual async Task> GetResponse(IRequest request, JsonSerializer? deserializer, CancellationToken cancellationToken) { try { @@ -238,12 +243,12 @@ namespace CryptoExchange.Net if (error != null) return WebCallResult.CreateErrorResult(response.StatusCode, response.ResponseHeaders, error); - var deserializeResult = Deserialize(parseResult.Data, null, null, request.RequestId); + var deserializeResult = Deserialize(parseResult.Data, null, deserializer, request.RequestId); return new WebCallResult(response.StatusCode, response.ResponseHeaders, deserializeResult.Data, deserializeResult.Error); } else { - var desResult = await Deserialize(responseStream, null, request.RequestId, sw.ElapsedMilliseconds).ConfigureAwait(false); + var desResult = await Deserialize(responseStream, deserializer, request.RequestId, sw.ElapsedMilliseconds).ConfigureAwait(false); responseStream.Close(); response.Close();