1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-12 17:03:10 +00:00

Compare commits

..

7 Commits

Author SHA1 Message Date
JKorf d91755dff5 Updated version 2024-01-09 18:37:11 +01:00
JKorf 27d49a6093 Added support null and empty string values to BoolConverter 2024-01-09 18:36:20 +01:00
JKorf ad1bdd9a3f Fixed error 2024-01-04 21:33:10 +01:00
JKorf 4f2d7abc7e Updated version 2024-01-04 21:32:27 +01:00
JKorf ef9de5e338 Fixed parsing of string datetime value "0.00000" 2024-01-04 21:31:51 +01:00
JKorf 8b513e51b9 Updated version 2023-12-02 15:17:34 +01:00
JKorf d43b38a23a Fix requestBodyFormat parameter usage 2023-12-02 15:15:38 +01:00
6 changed files with 83 additions and 9 deletions
@@ -20,6 +20,8 @@ namespace CryptoExchange.Net.UnitTests
[TestCase("1620777600000")] [TestCase("1620777600000")]
[TestCase("2021-05-12T00:00:00.000Z")] [TestCase("2021-05-12T00:00:00.000Z")]
[TestCase("2021-05-12T00:00:00.000000000Z")] [TestCase("2021-05-12T00:00:00.000000000Z")]
[TestCase("0.000000", true)]
[TestCase("0", true)]
[TestCase("", true)] [TestCase("", true)]
[TestCase(" ", true)] [TestCase(" ", true)]
public void TestDateTimeConverterString(string input, bool expectNull = false) public void TestDateTimeConverterString(string input, bool expectNull = false)
@@ -162,6 +164,44 @@ namespace CryptoExchange.Net.UnitTests
var output = JsonConvert.DeserializeObject<NotNullableEnumObject>($"{{ \"Value\": {val} }}"); var output = JsonConvert.DeserializeObject<NotNullableEnumObject>($"{{ \"Value\": {val} }}");
Assert.AreEqual(output.Value, expected); Assert.AreEqual(output.Value, expected);
} }
[TestCase("1", true)]
[TestCase("true", true)]
[TestCase("yes", true)]
[TestCase("y", true)]
[TestCase("on", true)]
[TestCase("-1", false)]
[TestCase("0", false)]
[TestCase("n", false)]
[TestCase("no", false)]
[TestCase("false", false)]
[TestCase("off", false)]
[TestCase("", null)]
public void TestBoolConverter(string value, bool? expected)
{
var val = value == null ? "null" : $"\"{value}\"";
var output = JsonConvert.DeserializeObject<BoolObject>($"{{ \"Value\": {val} }}");
Assert.AreEqual(output.Value, expected);
}
[TestCase("1", true)]
[TestCase("true", true)]
[TestCase("yes", true)]
[TestCase("y", true)]
[TestCase("on", true)]
[TestCase("-1", false)]
[TestCase("0", false)]
[TestCase("n", false)]
[TestCase("no", false)]
[TestCase("false", false)]
[TestCase("off", false)]
[TestCase("", false)]
public void TestBoolConverterNotNullable(string value, bool expected)
{
var val = value == null ? "null" : $"\"{value}\"";
var output = JsonConvert.DeserializeObject<NotNullableBoolObject>($"{{ \"Value\": {val} }}");
Assert.AreEqual(output.Value, expected);
}
} }
public class TimeObject public class TimeObject
@@ -180,6 +220,18 @@ namespace CryptoExchange.Net.UnitTests
public TestEnum Value { get; set; } public TestEnum Value { get; set; }
} }
public class BoolObject
{
[JsonConverter(typeof(BoolConverter))]
public bool? Value { get; set; }
}
public class NotNullableBoolObject
{
[JsonConverter(typeof(BoolConverter))]
public bool Value { get; set; }
}
[JsonConverter(typeof(EnumConverter))] [JsonConverter(typeof(EnumConverter))]
public enum TestEnum public enum TestEnum
{ {
+3 -3
View File
@@ -515,7 +515,7 @@ namespace CryptoExchange.Net
if (parameterPosition == HttpMethodParameterPosition.InBody) if (parameterPosition == HttpMethodParameterPosition.InBody)
{ {
var contentType = requestBodyFormat == RequestBodyFormat.Json ? Constants.JsonContentHeader : Constants.FormContentHeader; var contentType = bodyFormat == RequestBodyFormat.Json ? Constants.JsonContentHeader : Constants.FormContentHeader;
if (bodyParameters.Any()) if (bodyParameters.Any())
WriteParamBody(request, bodyParameters, contentType); WriteParamBody(request, bodyParameters, contentType);
else else
@@ -533,13 +533,13 @@ namespace CryptoExchange.Net
/// <param name="contentType">The content type of the data</param> /// <param name="contentType">The content type of the data</param>
protected virtual void WriteParamBody(IRequest request, SortedDictionary<string, object> parameters, string contentType) protected virtual void WriteParamBody(IRequest request, SortedDictionary<string, object> parameters, string contentType)
{ {
if (requestBodyFormat == RequestBodyFormat.Json) if (contentType == Constants.JsonContentHeader)
{ {
// Write the parameters as json in the body // Write the parameters as json in the body
var stringData = JsonConvert.SerializeObject(parameters); var stringData = JsonConvert.SerializeObject(parameters);
request.SetContent(stringData, contentType); request.SetContent(stringData, contentType);
} }
else if (requestBodyFormat == RequestBodyFormat.FormData) else if (contentType == Constants.FormContentHeader)
{ {
// Write the parameters as form data in the body // Write the parameters as form data in the body
var stringData = parameters.ToFormData(); var stringData = parameters.ToFormData();
+10 -1
View File
@@ -34,7 +34,16 @@ namespace CryptoExchange.Net.Converters
/// </returns> /// </returns>
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{ {
switch (reader.Value?.ToString().ToLower().Trim()) var value = reader.Value?.ToString().ToLower().Trim();
if (value == null || value == "")
{
if (Nullable.GetUnderlyingType(objectType) != null)
return null;
return false;
}
switch (value)
{ {
case "true": case "true":
case "yes": case "yes":
@@ -59,8 +59,12 @@ namespace CryptoExchange.Net.Converters
if (string.IsNullOrWhiteSpace(stringValue)) if (string.IsNullOrWhiteSpace(stringValue))
return null; return null;
if (string.IsNullOrWhiteSpace(stringValue) || stringValue == "0" || stringValue == "-1") if (string.IsNullOrWhiteSpace(stringValue)
|| stringValue == "-1"
|| (double.TryParse(stringValue, out var doubleVal) && doubleVal == 0))
{
return objectType == typeof(DateTime) ? default(DateTime) : null; return objectType == typeof(DateTime) ? default(DateTime) : null;
}
if (stringValue.Length == 8) if (stringValue.Length == 8)
{ {
+4 -4
View File
@@ -6,16 +6,16 @@
<PackageId>CryptoExchange.Net</PackageId> <PackageId>CryptoExchange.Net</PackageId>
<Authors>JKorf</Authors> <Authors>JKorf</Authors>
<Description>A base package for implementing cryptocurrency API's</Description> <Description>A base package for implementing cryptocurrency API's</Description>
<PackageVersion>6.2.2</PackageVersion> <PackageVersion>6.2.5</PackageVersion>
<AssemblyVersion>6.2.2</AssemblyVersion> <AssemblyVersion>6.2.5</AssemblyVersion>
<FileVersion>6.2.2</FileVersion> <FileVersion>6.2.5</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/JKorf/CryptoExchange.Net.git</RepositoryUrl> <RepositoryUrl>https://github.com/JKorf/CryptoExchange.Net.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/JKorf/CryptoExchange.Net</PackageProjectUrl> <PackageProjectUrl>https://github.com/JKorf/CryptoExchange.Net</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage> <NeutralLanguage>en</NeutralLanguage>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReleaseNotes>6.2.2 - Added support for specifying the request body content type on a per request basis, Added DecimalStringWriterConverter, Added RequestId to WebCallResult model, Updated response logging</PackageReleaseNotes> <PackageReleaseNotes>6.2.5 - Added support for deserializing null and empty string values to BoolConverter</PackageReleaseNotes>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
+9
View File
@@ -31,6 +31,15 @@ Make a one time donation in a crypto currency of your choice. If you prefer to d
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf). Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf).
## Release notes ## Release notes
* Version 6.2.5 - 09 Jan 2024
* Added support for deserializing null and empty string values to BoolConverter
* Version 6.2.4 - 04 Jan 2024
* Fixed parsing of DateTime value of zero with additional zero decimal places
* Version 6.2.3 - 02 Dec 2023
* Fixed requestBodyFormat parameter handling
* Version 6.2.2 - 02 Dec 2023 * Version 6.2.2 - 02 Dec 2023
* Added support for specifying the request body content type on a per request basis * Added support for specifying the request body content type on a per request basis
* Added DecimalStringWriterConverter * Added DecimalStringWriterConverter