cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/4] cordova-wp8 git commit: Revert JsonHelper to pre Newtonsoft implementation
Date Fri, 15 May 2015 00:33:22 GMT
Repository: cordova-wp8
Updated Branches:
  refs/heads/master 14b6cc3e8 -> 3ef90c084


Revert JsonHelper to pre Newtonsoft implementation


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/c4498b34
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/c4498b34
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/c4498b34

Branch: refs/heads/master
Commit: c4498b3416e6a368b61a559292a6a08ba0b8f3f8
Parents: f3ce53f
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Thu May 14 14:46:48 2015 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Thu May 14 14:46:48 2015 -0700

----------------------------------------------------------------------
 template/cordovalib/JSON/JsonHelper.cs | 48 +++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c4498b34/template/cordovalib/JSON/JsonHelper.cs
----------------------------------------------------------------------
diff --git a/template/cordovalib/JSON/JsonHelper.cs b/template/cordovalib/JSON/JsonHelper.cs
index 63956c0..77c7233 100644
--- a/template/cordovalib/JSON/JsonHelper.cs
+++ b/template/cordovalib/JSON/JsonHelper.cs
@@ -12,7 +12,11 @@
 	limitations under the License.
 */
 
-using Newtonsoft.Json;
+using System;
+using System.Runtime.Serialization.Json;
+using System.IO;
+using System.Text;
+using System.Diagnostics;
 
 namespace WPCordovaClassLib.Cordova.JSON
 {
@@ -28,7 +32,29 @@ namespace WPCordovaClassLib.Cordova.JSON
         /// <returns>JSON representation of the object. Returns 'null' string for null
passed as argument</returns>
         public static string Serialize(object obj)
         {
-            return JsonConvert.SerializeObject(obj);
+            if (obj == null)
+            {
+                return "null";
+            }
+
+            DataContractJsonSerializer ser = new DataContractJsonSerializer(obj.GetType());
+
+            MemoryStream ms = new MemoryStream();
+            ser.WriteObject(ms, obj);
+
+            ms.Position = 0;
+
+            string json = String.Empty;
+
+            using (StreamReader sr = new StreamReader(ms))
+            {
+                json = sr.ReadToEnd();
+            }
+
+            ms.Close();
+
+            return json;
+
         }
 
         /// <summary>
@@ -39,7 +65,23 @@ namespace WPCordovaClassLib.Cordova.JSON
         /// <returns>Deserialized object instance</returns>
         public static T Deserialize<T>(string json)
         {
-            return JsonConvert.DeserializeObject<T>(json);
+            DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T));
+            object result = null;
+            try
+            {
+                using (MemoryStream mem = new MemoryStream(Encoding.UTF8.GetBytes(json)))
+                {
+                    result = deserializer.ReadObject(mem);
+                }
+            }
+            catch (Exception ex)
+            {
+                Debug.WriteLine(ex.Message);
+                Debug.WriteLine("Failed to deserialize " + typeof(T) + " with JSON value
:: " + json);
+            }
+
+            return (T)result;
+
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message