26 lines
700 B
C#
26 lines
700 B
C#
using Newtonsoft.Json;
|
|
using System;
|
|
|
|
namespace TMDbLib.Utilities.Converters
|
|
{
|
|
public class TmdbNullIntAsZero : 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;
|
|
|
|
return Convert.ToInt32(reader.Value);
|
|
}
|
|
|
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|
{
|
|
writer.WriteValue(value?.ToString());
|
|
}
|
|
}
|
|
} |