diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index 5571588c8..7b4b02b63 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Net; using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Model.Entities; +using MediaBrowser.Common.Json; namespace MediaBrowser.Api.HttpHandlers { @@ -21,24 +22,19 @@ namespace MediaBrowser.Api.HttpHandlers public static object GetSerializationObject(BaseItem item, bool includeChildren) { - Folder folder = item as Folder; - - if (includeChildren && folder != null) + if (includeChildren && item.IsFolder) { + Folder folder = item as Folder; + return new { BaseItem = item, - Children = folder.Children, - Type = item.GetType().Name + Children = folder.Children }; } else { - return new - { - BaseItem = item, - Type = item.GetType().Name - }; + return item; } } diff --git a/MediaBrowser.Common/Json/JsonSerializer.cs b/MediaBrowser.Common/Json/JsonSerializer.cs index 903482fc8..55663357a 100644 --- a/MediaBrowser.Common/Json/JsonSerializer.cs +++ b/MediaBrowser.Common/Json/JsonSerializer.cs @@ -1,55 +1,55 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; +using System.IO; namespace MediaBrowser.Common.Json { public class JsonSerializer { - public static void Serialize(T o, Stream stream) + public static void SerializeToStream(T o, Stream stream) { - using (StreamWriter streamWriter = new StreamWriter(stream)) - { - using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(streamWriter)) - { - var settings = new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore - }; - - Newtonsoft.Json.JsonSerializer.Create(settings).Serialize(writer, o); - } - } + Configure(); + + ServiceStack.Text.JsonSerializer.SerializeToStream(o, stream); } - public static void Serialize(T o, string file) + public static void SerializeToFile(T o, string file) { + Configure(); + using (StreamWriter streamWriter = new StreamWriter(file)) { - using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(streamWriter)) - { - var settings = new Newtonsoft.Json.JsonSerializerSettings() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore - }; - - Newtonsoft.Json.JsonSerializer.Create(settings).Serialize(writer, o); - } + ServiceStack.Text.JsonSerializer.SerializeToWriter(o, streamWriter); } } - public static T Deserialize(string file) + public static T DeserializeFromFile(string file) { - using (StreamReader streamReader = new StreamReader(file)) + Configure(); + + using (Stream stream = File.OpenRead(file)) { - using (Newtonsoft.Json.JsonTextReader reader = new Newtonsoft.Json.JsonTextReader(streamReader)) - { - return Newtonsoft.Json.JsonSerializer.Create(new Newtonsoft.Json.JsonSerializerSettings() { }).Deserialize(reader); - } + return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); } } + + public static T DeserializeFromStream(Stream stream) + { + Configure(); + + return ServiceStack.Text.JsonSerializer.DeserializeFromStream(stream); + } + + public static T DeserializeFromString(string data) + { + Configure(); + + return ServiceStack.Text.JsonSerializer.DeserializeFromString(data); + } + + private static void Configure() + { + ServiceStack.Text.JsConfig.ExcludeTypeInfo = true; + ServiceStack.Text.JsConfig.IncludeNullValues = false; + ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601; + } } } diff --git a/MediaBrowser.Common/Logging/BaseLogger.cs b/MediaBrowser.Common/Logging/BaseLogger.cs index 51c6632d5..407c8baa7 100644 --- a/MediaBrowser.Common/Logging/BaseLogger.cs +++ b/MediaBrowser.Common/Logging/BaseLogger.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Text; using System.Threading; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Logging { diff --git a/MediaBrowser.Common/Logging/LogRow.cs b/MediaBrowser.Common/Logging/LogRow.cs index 39c69eb45..d1e234250 100644 --- a/MediaBrowser.Common/Logging/LogRow.cs +++ b/MediaBrowser.Common/Logging/LogRow.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Common.Logging { diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 3c7f0ff04..8ee14d3a9 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -30,9 +30,6 @@ 4 - - ..\packages\Newtonsoft.Json.4.5.7\lib\net40\Newtonsoft.Json.dll - ..\packages\ServiceStack.Text.3.8.5\lib\net35\ServiceStack.Text.dll @@ -50,6 +47,7 @@ + @@ -63,7 +61,6 @@ - @@ -71,6 +68,12 @@ + + + {9b1ddd79-5134-4df3-ace3-d1957a7350d8} + MediaBrowser.Model + +