Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nullvaluehandling on dealupdate #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Pipedrive.net/Converters/CustomFieldConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pipedrive.net/Models/Request/Deals/DealUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Pipedrive
{
[JsonConverter(typeof(CustomFieldConverter))]
[JsonConverter(typeof(CustomFieldConverter), NullValueHandling.Ignore)]
public class DealUpdate : IEntityWithCustomFields
{
[JsonProperty("title")]
Expand Down Expand Up @@ -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; }
Expand Down