[longomatch] Default to JSON serialization



commit 14e4d8b931be60190f7894c5d6c60c843a461047
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed May 28 16:14:21 2014 +0200

    Default to JSON serialization

 LongoMatch.Core/Common/SerializableObject.cs |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/LongoMatch.Core/Common/SerializableObject.cs b/LongoMatch.Core/Common/SerializableObject.cs
index 4d8c497..458d0c5 100644
--- a/LongoMatch.Core/Common/SerializableObject.cs
+++ b/LongoMatch.Core/Common/SerializableObject.cs
@@ -33,7 +33,7 @@ namespace LongoMatch.Common
        public class SerializableObject
        {
                public static void Save<T>(T obj, Stream stream,
-                                          SerializationType type=SerializationType.Binary) {
+                                          SerializationType type=SerializationType.Json) {
                        switch (type) {
                        case SerializationType.Binary:
                                BinaryFormatter formatter = new  BinaryFormatter();
@@ -52,7 +52,7 @@ namespace LongoMatch.Common
                }
                
                public static void Save<T>(T obj, string filepath,
-                                          SerializationType type=SerializationType.Binary) {
+                                          SerializationType type=SerializationType.Json) {
                        Stream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, 
FileShare.None);
                        using (stream) {
                                Save<T> (obj, stream, type);
@@ -61,7 +61,7 @@ namespace LongoMatch.Common
                }
 
                public static T Load<T>(Stream stream,
-                                       SerializationType type=SerializationType.Binary) {
+                                       SerializationType type=SerializationType.Json) {
                        switch (type) {
                        case SerializationType.Binary:
                                BinaryFormatter formatter = new BinaryFormatter();
@@ -78,7 +78,7 @@ namespace LongoMatch.Common
                }
                
                public static T Load<T>(string filepath,
-                                       SerializationType type=SerializationType.Binary) {
+                                       SerializationType type=SerializationType.Json) {
                        Stream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, 
FileShare.Read);
                        using (stream) {
                                return Load<T> (stream, type);
@@ -91,9 +91,10 @@ namespace LongoMatch.Common
                                                       FileAccess.Read, FileShare.Read);
                        using (stream) {
                                try {
+                                       return Load<T> (stream, SerializationType.Json);
+                               } catch (Exception e) {
+                                       Log.Exception (e);
                                        return Load<T> (stream, SerializationType.Binary);
-                               } catch {
-                                       return Load<T> (stream, SerializationType.Xml);
                                }
                        }
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]