Skip to content

Commit

Permalink
Fixed some warnings, added support for number deserialization when re…
Browse files Browse the repository at this point in the history
…questing string in STJ MessageAccessor.GetValue<T>
  • Loading branch information
JKorf committed Aug 6, 2024
1 parent 7be75f7 commit 637070a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
26 changes: 10 additions & 16 deletions CryptoExchange.Net/Clients/RestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@ protected virtual IRequest ConstructRequest(
}

var headers = new Dictionary<string, string>();
var uriParameters = parameterPosition == HttpMethodParameterPosition.InUri ? CreateParameterDictionary(parameters) : new Dictionary<string, object>();
var bodyParameters = parameterPosition == HttpMethodParameterPosition.InBody ? CreateParameterDictionary(parameters) : new Dictionary<string, object>();
var uriParameters = parameterPosition == HttpMethodParameterPosition.InUri ? CreateParameterDictionary(parameters) : null;
var bodyParameters = parameterPosition == HttpMethodParameterPosition.InBody ? CreateParameterDictionary(parameters) : null;
if (AuthenticationProvider != null)
{
try
Expand All @@ -837,24 +837,18 @@ protected virtual IRequest ConstructRequest(
}
}

// Sanity check
foreach (var param in parameters)
{
if (!uriParameters.ContainsKey(param.Key) && !bodyParameters.ContainsKey(param.Key))
{
throw new Exception($"Missing parameter {param.Key} after authentication processing. AuthenticationProvider implementation " +
$"should return provided parameters in either the uri or body parameters output");
}
}

// Add the auth parameters to the uri, start with a new URI to be able to sort the parameters including the auth parameters
uri = uri.SetParameters(uriParameters, arraySerialization);
if (uriParameters != null)
uri = uri.SetParameters(uriParameters, arraySerialization);

var request = RequestFactory.Create(method, uri, requestId);
request.Accept = Constants.JsonContentHeader;

foreach (var header in headers)
request.AddHeader(header.Key, header.Value);
if (headers != null)
{
foreach (var header in headers)
request.AddHeader(header.Key, header.Value);
}

if (additionalHeaders != null)
{
Expand All @@ -875,7 +869,7 @@ protected virtual IRequest ConstructRequest(
if (parameterPosition == HttpMethodParameterPosition.InBody)
{
var contentType = bodyFormat == RequestBodyFormat.Json ? Constants.JsonContentHeader : Constants.FormContentHeader;
if (bodyParameters.Any())
if (bodyParameters?.Any() == true)
WriteParamBody(request, bodyParameters, contentType);
else
request.SetContent(RequestBodyEmptyContent, contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public CallResult<T> Deserialize<T>(MessagePath? path = null)
if (value.Value.ValueKind == JsonValueKind.Object || value.Value.ValueKind == JsonValueKind.Array)
return default;

if (typeof(T) == typeof(string))
{
if (value.Value.ValueKind == JsonValueKind.Number)
return (T)(object)value.Value.GetInt64().ToString();
}

return value.Value.Deserialize<T>();
}

Expand Down

0 comments on commit 637070a

Please sign in to comment.