Skip to content

Commit

Permalink
Also return zero when reader value is empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed Apr 17, 2016
1 parent 2548d71 commit 3836097
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ShopifySharp/Converters/NullToZeroConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@

namespace ShopifySharp.Converters
{
class NullToZeroConverter:JsonConverter
{/// <summary>
/// A custom integer converter that converts null to zero
/// </summary>
/// <summary>
/// A custom integer converter that converts null to zero
/// </summary>
public class NullToZeroConverter:JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(int);
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.Value == null) return 0;
if (reader.Value == null || string.IsNullOrEmpty(reader.Value?.ToString())) return 0;
return Convert.ToInt32(reader.Value);
}

Expand Down

0 comments on commit 3836097

Please sign in to comment.