diff --git a/NzbDrone.Common/IJsonSerializer.cs b/NzbDrone.Common/IJsonSerializer.cs index ee3d86f76..17af14151 100644 --- a/NzbDrone.Common/IJsonSerializer.cs +++ b/NzbDrone.Common/IJsonSerializer.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -9,6 +10,7 @@ namespace NzbDrone.Common T Deserialize(string json) where T : class, new(); string Serialize(object obj); void Serialize(TModel model, Stream outputStream); + object Deserialize(string json, Type type); } public class JsonSerializer : IJsonSerializer @@ -42,6 +44,11 @@ namespace NzbDrone.Common return JsonConvert.DeserializeObject(json); } + public object Deserialize(string json, Type type) + { + return JsonConvert.DeserializeObject(json, type); + } + public string Serialize(object obj) { return JsonConvert.SerializeObject(obj); @@ -54,5 +61,7 @@ namespace NzbDrone.Common _jsonNetSerializer.Serialize(jsonTextWriter, model); jsonTextWriter.Flush(); } + + } } \ No newline at end of file diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 7010e9995..2e8709719 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -1,4 +1,4 @@ - + Debug @@ -67,7 +67,7 @@ False - ..\packages\Newtonsoft.Json.5.0.2\lib\net35\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.5.0.3\lib\net35\Newtonsoft.Json.dll False diff --git a/NzbDrone.Common/packages.config b/NzbDrone.Common/packages.config index bd30b2acd..5fc560601 100644 --- a/NzbDrone.Common/packages.config +++ b/NzbDrone.Common/packages.config @@ -1,8 +1,8 @@ - + - + \ No newline at end of file diff --git a/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs b/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs index 6300c6568..4b9bd4118 100644 --- a/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs +++ b/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using FluentAssertions; using Marr.Data; using NUnit.Framework; +using NzbDrone.Common; using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Converters; using NzbDrone.Core.Tv; @@ -40,8 +41,8 @@ namespace NzbDrone.Core.Test.Datastore [SetUp] public void Setup() { - MapRepository.Instance.RegisterTypeConverter(typeof(List), new EmbeddedDocumentConverter()); - MapRepository.Instance.RegisterTypeConverter(typeof(EmbeddedType), new EmbeddedDocumentConverter()); + MapRepository.Instance.RegisterTypeConverter(typeof(List), new EmbeddedDocumentConverter(new JsonSerializer())); + MapRepository.Instance.RegisterTypeConverter(typeof(EmbeddedType), new EmbeddedDocumentConverter(new JsonSerializer())); MapRepository.Instance.RegisterTypeConverter(typeof(Int32), new Int32Converter()); } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 0dddbc9b5..a2102d120 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -1,4 +1,4 @@ - + Debug @@ -93,7 +93,7 @@ False - ..\packages\Newtonsoft.Json.5.0.2\lib\net35\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.5.0.3\lib\net35\Newtonsoft.Json.dll False diff --git a/NzbDrone.Core.Test/packages.config b/NzbDrone.Core.Test/packages.config index 58fd5565c..36539bf4d 100644 --- a/NzbDrone.Core.Test/packages.config +++ b/NzbDrone.Core.Test/packages.config @@ -1,4 +1,4 @@ - + @@ -7,7 +7,7 @@ - + diff --git a/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs b/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs index 428120be9..12ddfc693 100644 --- a/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs +++ b/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using NLog; -using Newtonsoft.Json; using NzbDrone.Common; using NzbDrone.Core.Configuration; @@ -17,12 +16,14 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries { private readonly IHttpProvider _httpProvider; private readonly IConfigService _configService; + private readonly IJsonSerializer _jsonSerializer; private readonly Logger _logger; - public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, Logger logger) + public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, IJsonSerializer jsonSerializer, Logger logger) { _httpProvider = httpProvider; _configService = configService; + _jsonSerializer = jsonSerializer; _logger = logger; } @@ -32,7 +33,7 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries { var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds"); - var seriesIds = JsonConvert.DeserializeObject>(dailySeriesIds); + var seriesIds = _jsonSerializer.Deserialize>(dailySeriesIds); return seriesIds; } diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs index 757be3928..28d6f4d48 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; using NzbDrone.Common; using NzbDrone.Core.Configuration; @@ -14,17 +13,19 @@ namespace NzbDrone.Core.DataAugmentation.Scene { private readonly IHttpProvider _httpProvider; private readonly IConfigService _configService; + private readonly IJsonSerializer _jsonSerializer; - public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService) + public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService, IJsonSerializer jsonSerializer) { _httpProvider = httpProvider; _configService = configService; + _jsonSerializer = jsonSerializer; } public List Fetch() { var mappingsJson = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/SceneMapping/Active"); - return JsonConvert.DeserializeObject>(mappingsJson); + return _jsonSerializer.Deserialize>(mappingsJson); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs b/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs index e71fb3954..845796b81 100644 --- a/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs +++ b/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs @@ -1,12 +1,19 @@ using System; using Marr.Data.Converters; using Marr.Data.Mapping; -using Newtonsoft.Json; +using NzbDrone.Common; namespace NzbDrone.Core.Datastore.Converters { public class EmbeddedDocumentConverter : IConverter { + private readonly IJsonSerializer _serializer; + + public EmbeddedDocumentConverter(IJsonSerializer serializer) + { + _serializer = serializer; + } + public object FromDB(ColumnMap map, object dbValue) { if (dbValue == DBNull.Value) @@ -21,14 +28,14 @@ namespace NzbDrone.Core.Datastore.Converters return null; } - return JsonConvert.DeserializeObject(stringValue, map.FieldType); + return _serializer.Deserialize(stringValue, map.FieldType); } public object ToDB(object clrValue) { if (clrValue == null) return null; - var json = JsonConvert.SerializeObject(clrValue); + var json = _serializer.Serialize(clrValue); return json; } diff --git a/NzbDrone.Core/Datastore/TableMapping.cs b/NzbDrone.Core/Datastore/TableMapping.cs index 0c853ae97..e0893b627 100644 --- a/NzbDrone.Core/Datastore/TableMapping.cs +++ b/NzbDrone.Core/Datastore/TableMapping.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using Marr.Data; using Marr.Data.Mapping; +using NzbDrone.Common; using NzbDrone.Core.Configuration; -using NzbDrone.Core.DataAugmentation; using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.Datastore.Converters; using NzbDrone.Core.ExternalNotification; @@ -75,7 +75,7 @@ namespace NzbDrone.Core.Datastore .Where(c => c.GetInterfaces().Any(i => i == typeof(IEmbeddedDocument))); - var embeddedConvertor = new EmbeddedDocumentConverter(); + var embeddedConvertor = new EmbeddedDocumentConverter(new JsonSerializer()); var genericListDefinition = typeof(List<>).GetGenericTypeDefinition(); foreach (var embeddedType in embeddedTypes) { diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index dff681406..cb207b25b 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -1,4 +1,4 @@ - + Debug @@ -144,7 +144,7 @@ False - ..\packages\Newtonsoft.Json.5.0.2\lib\net35\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.5.0.3\lib\net35\Newtonsoft.Json.dll False @@ -171,9 +171,6 @@ - - ..\packages\twitterizer.2.4.0.26532\lib\net40\Twitterizer2.dll - @@ -370,7 +367,6 @@ - @@ -445,9 +441,6 @@ Code - - Code - Code @@ -498,9 +491,6 @@ Code - - Code - Code diff --git a/NzbDrone.Core/packages.config b/NzbDrone.Core/packages.config index 82d976ee4..5e6b29805 100644 --- a/NzbDrone.Core/packages.config +++ b/NzbDrone.Core/packages.config @@ -1,12 +1,11 @@ - + - + - \ No newline at end of file diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 9143aa0f5..799d6d058 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -74,6 +74,7 @@ namespace NzbDrone.Test.Common Mocker.SetConstant(LogManager.GetLogger("TestLogger")); + Mocker.SetConstant(new JsonSerializer()); LogManager.ReconfigExistingLoggers();