Skip to content
This repository
tree: d29b2433c0
Fetching contributors…

Cannot retrieve contributors at this time

file 35 lines (31 sloc) 1.062 kb
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
using System.Globalization;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using RestSharp;
using RestSharp.Deserializers;

namespace GoCardlessSdk.Helpers
{
    public class NewtonsoftJsonDeserializer : IDeserializer
    {
        private readonly JsonSerializer _serializer;
        public string RootElement { get; set; }
        public string Namespace { get; set; }
        public string DateFormat { get; set; }
        public CultureInfo Culture { get; set; }
 
        public NewtonsoftJsonDeserializer(JsonSerializer serializer)
        {
            this._serializer = serializer;
            Culture = CultureInfo.InvariantCulture;
        }

        public T Deserialize<T>(RestResponse response) where T : new()
        {
            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(response.Content)))
            using (var streamReader = new StreamReader(ms))
            using (var jtr = new JsonTextReader(streamReader))
            {
                return _serializer.Deserialize<T>(jtr);
            }
        }

    }
}
Something went wrong with that request. Please try again.