diff --git a/src/Pipedrive.net/Converters/CustomFieldConverter.cs b/src/Pipedrive.net/Converters/CustomFieldConverter.cs index 0edbce8d..07fefd0e 100644 --- a/src/Pipedrive.net/Converters/CustomFieldConverter.cs +++ b/src/Pipedrive.net/Converters/CustomFieldConverter.cs @@ -11,6 +11,17 @@ namespace Pipedrive.Internal { public class CustomFieldConverter : JsonConverter { + private readonly NullValueHandling? _nullValueHandling; + + public CustomFieldConverter() + { + } + + public CustomFieldConverter(NullValueHandling nullValueHandling) + { + _nullValueHandling = nullValueHandling; + } + public override bool CanConvert(Type objectType) { return typeof(IEntityWithCustomFields).IsAssignableFrom(objectType); @@ -178,9 +189,13 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s if (property.Ignored) continue; if (!ShouldSerialize(property, value)) continue; - var property_name = property.PropertyName; var property_value = property.ValueProvider.GetValue(value); + if (property.NullValueHandling == NullValueHandling.Ignore && property_value == null) continue; + if (_nullValueHandling == NullValueHandling.Ignore && property_value == null) continue; + + var property_name = property.PropertyName; + writer.WritePropertyName(property_name); if (property.Converter != null && property.Converter.CanWrite) { diff --git a/src/Pipedrive.net/Models/Request/Deals/DealUpdate.cs b/src/Pipedrive.net/Models/Request/Deals/DealUpdate.cs index aacee82f..ac421bac 100644 --- a/src/Pipedrive.net/Models/Request/Deals/DealUpdate.cs +++ b/src/Pipedrive.net/Models/Request/Deals/DealUpdate.cs @@ -6,7 +6,7 @@ namespace Pipedrive { - [JsonConverter(typeof(CustomFieldConverter))] + [JsonConverter(typeof(CustomFieldConverter), NullValueHandling.Ignore)] public class DealUpdate : IEntityWithCustomFields { [JsonProperty("title")] @@ -41,7 +41,7 @@ public class DealUpdate : IEntityWithCustomFields public string LostReason { get; set; } [JsonProperty("visible_to")] - public Visibility VisibleTo { get; set; } + public Visibility? VisibleTo { get; set; } [JsonProperty("add_time")] public DateTime? AddTime { get; set; }