Tweaked json and jsv serializers

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti 2012-08-22 13:01:05 -04:00
parent 020c20bd7d
commit a2f120b76b
2 changed files with 18 additions and 9 deletions

View File

@ -19,9 +19,9 @@ namespace MediaBrowser.Common.Serialization
{ {
Configure(); Configure();
using (StreamWriter streamWriter = new StreamWriter(file)) using (Stream stream = File.Open(file, FileMode.Create))
{ {
ServiceStack.Text.JsonSerializer.SerializeToWriter<T>(obj, streamWriter); ServiceStack.Text.JsonSerializer.SerializeToStream<T>(obj, stream);
} }
} }
@ -52,13 +52,6 @@ namespace MediaBrowser.Common.Serialization
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream); return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
} }
public static T DeserializeFromString<T>(string data)
{
Configure();
return ServiceStack.Text.JsonSerializer.DeserializeFromString<T>(data);
}
private static bool IsConfigured = false; private static bool IsConfigured = false;
private static void Configure() private static void Configure()
{ {

View File

@ -18,5 +18,21 @@ namespace MediaBrowser.Common.Serialization
{ {
return ServiceStack.Text.TypeSerializer.DeserializeFromStream<T>(stream); return ServiceStack.Text.TypeSerializer.DeserializeFromStream<T>(stream);
} }
public static void SerializeToFile<T>(T obj, string file)
{
using (Stream stream = File.Open(file, FileMode.Create))
{
ServiceStack.Text.TypeSerializer.SerializeToStream<T>(obj, stream);
}
}
public static T DeserializeFromFile<T>(string file)
{
using (Stream stream = File.OpenRead(file))
{
return ServiceStack.Text.TypeSerializer.DeserializeFromStream<T>(stream);
}
}
} }
} }