jellyfin/MediaBrowser.Common/Json/JsonSerializer.cs

54 lines
1.6 KiB
C#
Raw Normal View History

using System;
using System.IO;
2012-07-12 06:55:27 +00:00
namespace MediaBrowser.Common.Json
{
public class JsonSerializer
{
public static void SerializeToStream<T>(T obj, Stream stream)
2012-07-12 06:55:27 +00:00
{
ServiceStack.Text.JsonSerializer.SerializeToStream<T>(obj, stream);
2012-07-12 06:55:27 +00:00
}
public static void SerializeToFile<T>(T obj, string file)
2012-07-12 06:55:27 +00:00
{
using (StreamWriter streamWriter = new StreamWriter(file))
{
ServiceStack.Text.JsonSerializer.SerializeToWriter<T>(obj, streamWriter);
2012-07-12 06:55:27 +00:00
}
}
public static object DeserializeFromFile(Type type, string file)
{
using (Stream stream = File.OpenRead(file))
{
return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream);
}
}
public static T DeserializeFromFile<T>(string file)
2012-07-12 06:55:27 +00:00
{
using (Stream stream = File.OpenRead(file))
2012-07-12 06:55:27 +00:00
{
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
2012-07-12 06:55:27 +00:00
}
}
public static T DeserializeFromStream<T>(Stream stream)
{
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
}
public static T DeserializeFromString<T>(string data)
{
return ServiceStack.Text.JsonSerializer.DeserializeFromString<T>(data);
}
public static void Configure()
{
ServiceStack.Text.JsConfig.ExcludeTypeInfo = true;
ServiceStack.Text.JsConfig.IncludeNullValues = false;
}
2012-07-12 06:55:27 +00:00
}
}