1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 02:40:01 +00:00
Radarr/NzbDrone.Api/SignalR/Serializer.cs
2013-05-12 19:52:55 -07:00

37 lines
No EOL
959 B
C#

using System;
using System.IO;
using Microsoft.AspNet.SignalR.Json;
using NzbDrone.Common.Composition;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Api.SignalR
{
[Singleton]
public class Serializer : IJsonSerializer
{
private readonly JsonNetSerializer _signalRSerializer = new JsonNetSerializer();
public void Serialize(object value, TextWriter writer)
{
if (value.GetType().FullName.StartsWith("NzbDrone"))
{
Json.Serialize(value, writer);
}
else
{
_signalRSerializer.Serialize(value, writer);
}
}
public object Parse(string json, Type targetType)
{
if (targetType.FullName.StartsWith("NzbDrone"))
{
return Json.Deserialize(json, targetType);
}
return _signalRSerializer.Parse(json, targetType);
}
}
}