diff --git a/JsonSerializer.cs b/JsonSerializer.cs index 400f77c0d..34ac91955 100644 --- a/JsonSerializer.cs +++ b/JsonSerializer.cs @@ -29,7 +29,7 @@ public static void Serialize(string path, T obj) } } - public static bool Deserialize(string path, ref T obj) + public static bool Deserialize(string path, ref T obj) where T : new() { try { @@ -37,7 +37,12 @@ public static bool Deserialize(string path, ref T obj) using (var stream = new StreamReader(file, Encoding.UTF8)) using (var reader = new JsonTextReader(stream)) { - obj = Newtonsoft.Json.JsonSerializer.CreateDefault().Deserialize(reader); + var o = Newtonsoft.Json.JsonSerializer.CreateDefault().Deserialize(reader); + if (o == null) + { + o = new T(); + } + obj = o; return true; } }