Move to Newstonsoft.JSON for JSON serialisation
diff --git a/.gitignore b/.gitignore
index 3009f2e..e427378 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@
/temp/*
*.dll
+!template/lib/*
# Ignore template zip files
*.zip
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 />
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.
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 @@
/// <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 @@
/// <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);
}
}
}
diff --git a/template/lib/Newtonsoft.Json.dll b/template/lib/Newtonsoft.Json.dll
new file mode 100644
index 0000000..c1ac3db
--- /dev/null
+++ b/template/lib/Newtonsoft.Json.dll
Binary files differ