cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/5] cordova-wp8 git commit: Move to Newstonsoft.JSON for JSON serialisation
Date Wed, 06 May 2015 05:48:45 GMT
Repository: cordova-wp8
Updated Branches:
  refs/heads/master ac15e1312 -> f3ce53f66


Move to Newstonsoft.JSON for JSON serialisation


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

Branch: refs/heads/master
Commit: 418e51ea4f6c6cb644f18f0660efdd8b058644a5
Parents: ac15e13
Author: Brett Rudd <brettrudd@gmail.com>
Authored: Wed Apr 1 17:00:20 2015 -0700
Committer: Brett Rudd <brettrudd@gmail.com>
Committed: Wed Apr 1 17:00:20 2015 -0700

----------------------------------------------------------------------
 .gitignore                             |   1 +
 framework/WPCordovaClassLib.csproj     |   5 +++
 template/CordovaWP8AppProj.csproj      |   5 +++
 template/cordovalib/JSON/JsonHelper.cs |  58 ++--------------------------
 template/lib/Newtonsoft.Json.dll       | Bin 0 -> 477696 bytes
 5 files changed, 14 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/418e51ea/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 3009f2e..e427378 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ Thumbs.db
 /temp/*
 
 *.dll
+!template/lib/*
 
 # Ignore template zip files
 *.zip

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/418e51ea/framework/WPCordovaClassLib.csproj
----------------------------------------------------------------------
diff --git a/framework/WPCordovaClassLib.csproj b/framework/WPCordovaClassLib.csproj
index a2b36f0..cb82f2d 100644
--- a/framework/WPCordovaClassLib.csproj
+++ b/framework/WPCordovaClassLib.csproj
@@ -199,6 +199,11 @@
   <ItemGroup>
     <Folder Include="Plugins\" />
   </ItemGroup>
+  <ItemGroup>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed,
processorArchitecture=MSIL">
+      <HintPath>..\template\lib\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+  </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets"
/>
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets"
/>
   <ProjectExtensions />

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/418e51ea/template/CordovaWP8AppProj.csproj
----------------------------------------------------------------------
diff --git a/template/CordovaWP8AppProj.csproj b/template/CordovaWP8AppProj.csproj
index 66126e4..9f93fc4 100644
--- a/template/CordovaWP8AppProj.csproj
+++ b/template/CordovaWP8AppProj.csproj
@@ -226,6 +226,11 @@
   <ItemGroup>
     <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
   </ItemGroup>
+  <ItemGroup>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed,
processorArchitecture=MSIL">
+      <HintPath>lib\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+  </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets"
/>
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets"
/>
   <!-- To modify your build process, add your task inside one of the targets below and
uncomment it. 

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/418e51ea/template/cordovalib/JSON/JsonHelper.cs
----------------------------------------------------------------------
diff --git a/template/cordovalib/JSON/JsonHelper.cs b/template/cordovalib/JSON/JsonHelper.cs
index 44511f6..63956c0 100644
--- a/template/cordovalib/JSON/JsonHelper.cs
+++ b/template/cordovalib/JSON/JsonHelper.cs
@@ -12,21 +12,7 @@
 	limitations under the License.
 */
 
-using System;
-using System.Net;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Documents;
-using System.Windows.Ink;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Animation;
-using System.Windows.Shapes;
-using System.Runtime.Serialization.Json;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using System.Diagnostics;
+using Newtonsoft.Json;
 
 namespace WPCordovaClassLib.Cordova.JSON
 {
@@ -42,29 +28,7 @@ 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)
         {
-            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;
-
+            return JsonConvert.SerializeObject(obj);
         }
 
         /// <summary>
@@ -75,23 +39,7 @@ namespace WPCordovaClassLib.Cordova.JSON
         /// <returns>Deserialized object instance</returns>
         public static T Deserialize<T>(string 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;
-
+            return JsonConvert.DeserializeObject<T>(json);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/418e51ea/template/lib/Newtonsoft.Json.dll
----------------------------------------------------------------------
diff --git a/template/lib/Newtonsoft.Json.dll b/template/lib/Newtonsoft.Json.dll
new file mode 100644
index 0000000..c1ac3db
Binary files /dev/null and b/template/lib/Newtonsoft.Json.dll differ


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


Mime
View raw message