diff --git a/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs new file mode 100644 index 000000000..9be237fa6 --- /dev/null +++ b/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using ProtoBuf; +using ServiceStack.Text; + +namespace MediaBrowser.ApiInteraction +{ + public static class DataSerializer + { + public static T DeserializeFromStream(Stream stream, SerializationFormats format) + { + if (format == ApiInteraction.SerializationFormats.Protobuf) + { + return Serializer.Deserialize(stream); + } + if (format == ApiInteraction.SerializationFormats.Jsv) + { + return TypeSerializer.DeserializeFromStream(stream); + } + + return JsonSerializer.DeserializeFromStream(stream); + } + + public static object DeserializeFromStream(Stream stream, SerializationFormats format, Type type) + { + if (format == ApiInteraction.SerializationFormats.Protobuf) + { + throw new NotImplementedException(); + } + if (format == ApiInteraction.SerializationFormats.Jsv) + { + return TypeSerializer.DeserializeFromStream(type, stream); + } + + return JsonSerializer.DeserializeFromStream(type, stream); + } + + public static void Configure() + { + JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601; + JsConfig.ExcludeTypeInfo = true; + JsConfig.IncludeNullValues = false; + } + + public static bool CanDeSerializeJsv + { + get + { + return false; + } + } + } +} diff --git a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj index 45a64f374..51e08dd9d 100644 --- a/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj +++ b/MediaBrowser.ApiInteraction.Metro/MediaBrowser.ApiInteraction.Metro.csproj @@ -42,12 +42,10 @@ ApiClient.cs - - DataSerializer.cs - SerializationFormats.cs +