diff --git a/ShopifySharp.Tests/FalseToNullConverter_Tests.cs b/ShopifySharp.Tests/FalseToNullConverter_Tests.cs index a205a3234..2afaa4c2f 100644 --- a/ShopifySharp.Tests/FalseToNullConverter_Tests.cs +++ b/ShopifySharp.Tests/FalseToNullConverter_Tests.cs @@ -1,5 +1,7 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using ShopifySharp.Converters; +using ShopifySharp.Infrastructure; using Xunit; namespace ShopifySharp.Tests @@ -12,6 +14,25 @@ public FalseToNullConverter_Tests() } + [Fact] + public void SerializeChargeTest() + { + var charge = Serializer.Deserialize("{ \"test\" : true }"); + Assert.True(charge.Test); + + charge = Serializer.Deserialize("{ \"test\" : null }"); + Assert.False(charge.Test); + + charge = Serializer.Deserialize("{ \"test\" : false }"); + Assert.False(charge.Test); + + Assert.True(JObject.Parse(Serializer.Serialize(new RecurringCharge { Test = true })).Value("test")); + + Assert.Null(JObject.Parse(Serializer.Serialize(new RecurringCharge { Test = false })).Value("test")); + + Assert.Null(JObject.Parse(Serializer.Serialize(new RecurringCharge { Test = null })).Value("test")); + } + [Fact] public void SerializeTrue() { diff --git a/ShopifySharp/Entities/Charge.cs b/ShopifySharp/Entities/Charge.cs index 621386b51..1c55c06c8 100644 --- a/ShopifySharp/Entities/Charge.cs +++ b/ShopifySharp/Entities/Charge.cs @@ -55,7 +55,7 @@ public class Charge : ShopifyObject /// States whether or not the application charge is a test transaction. /// /// Valid values are 'true' or null. Needs a special converter to convert null to false and vice-versa. - [JsonProperty("test"), JsonConverter(typeof(FalseToNullConverter))] + [JsonProperty("test", NullValueHandling = NullValueHandling.Include), JsonConverter(typeof(FalseToNullConverter))] public bool? Test { get; set; } /// diff --git a/ShopifySharp/Entities/RecurringCharge.cs b/ShopifySharp/Entities/RecurringCharge.cs index 45cd2b1dc..87f36a96d 100644 --- a/ShopifySharp/Entities/RecurringCharge.cs +++ b/ShopifySharp/Entities/RecurringCharge.cs @@ -87,7 +87,7 @@ public class RecurringCharge : ShopifyObject /// States whether or not the application charge is a test transaction. /// /// Valid values are 'true' or null. Needs a special converter to convert null to false and vice-versa. - [JsonProperty("test"), JsonConverter(typeof(FalseToNullConverter))] + [JsonProperty("test", NullValueHandling = NullValueHandling.Include), JsonConverter(typeof(FalseToNullConverter))] public bool? Test { get; set; } ///