added custom IntConverter to get around the mono bug

http://json.codeplex.com/workitem/24176
This commit is contained in:
Keivan Beigi
2013-09-18 17:24:50 -07:00
parent 904061c2f0
commit 41c5619d1b
15 changed files with 122 additions and 56 deletions

View File

@@ -0,0 +1,39 @@
using System;
using Newtonsoft.Json;
namespace NzbDrone.Common.Serializer
{
public class IntConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
}
else
{
writer.WriteValue(value);
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (!CanConvert(objectType))
{
throw new JsonSerializationException("Can't convert type " + existingValue.GetType().FullName + " to number");
}
if (objectType == typeof(Int64))
{
return Convert.ToInt64(reader.Value);
}
return Convert.ToInt32(reader.Value);
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(Int32) || objectType == typeof(Int64) || objectType == typeof(int);
}
}
}