aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ApiInteraction.Metro/DataSerializer.cs
blob: 9be237fa6a27ecf382ffd68e707e4239ef66b585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.IO;
using ProtoBuf;
using ServiceStack.Text;

namespace MediaBrowser.ApiInteraction
{
    public static class DataSerializer
    {
        public static T DeserializeFromStream<T>(Stream stream, SerializationFormats format)
        {
            if (format == ApiInteraction.SerializationFormats.Protobuf)
            {
                return Serializer.Deserialize<T>(stream);
            }
            if (format == ApiInteraction.SerializationFormats.Jsv)
            {
                return TypeSerializer.DeserializeFromStream<T>(stream);
            }

            return JsonSerializer.DeserializeFromStream<T>(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;
            }
        }
    }
}