diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
index b2f53f9f55c..d89fc02aa6b 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj
@@ -124,9 +124,6 @@
2.0.1
-
- 4.7.2
-
1.0.5
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj b/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj
index bf18c15c898..d9cc96e80ce 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/Microsoft.Toolkit.Uwp.UI.Controls.csproj
@@ -47,6 +47,7 @@
+
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs
index 73311acfc88..bf724ac796e 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
+using System.Runtime.Serialization;
using System.Threading.Tasks;
using Windows.Storage;
@@ -20,7 +21,9 @@ public abstract class BaseObjectStorageHelper : IObjectStorageHelper
///
/// Initializes a new instance of the class,
/// which can read and write data using the provided ;
- /// if none is provided, a default Json serializer will be used.
+ /// if none is provided, a default Json serializer will be used (based on ).
+ /// In 6.1 and older the default Serializer was based on Newtonsoft.Json and the new default Serializer may behave differently.
+ /// To implement a based on Newtonsoft.Json or System.Text.Json see https://aka.ms/wct/storagehelper-migration
///
/// The serializer to use.
public BaseObjectStorageHelper(IObjectSerializer objectSerializer = null)
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs
index 3f1d52f6fbd..cb962714b2d 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs
@@ -2,14 +2,28 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Text.Json;
+using System.IO;
+using System.Runtime.Serialization.Json;
+using System.Text;
namespace Microsoft.Toolkit.Uwp.Helpers
{
internal class JsonObjectSerializer : IObjectSerializer
{
- public string Serialize(T value) => JsonSerializer.Serialize(value);
+ public string Serialize(T value)
+ {
+ using var sr = new MemoryStream();
- public T Deserialize(string value) => JsonSerializer.Deserialize(value);
+ new DataContractJsonSerializer(typeof(T)).WriteObject(sr, value);
+ var json = sr.ToArray();
+ return Encoding.UTF8.GetString(json, 0, json.Length);
+ }
+
+ public T Deserialize(string value)
+ {
+ using var ms = new MemoryStream(Encoding.UTF8.GetBytes(value));
+
+ return (T)new DataContractJsonSerializer(typeof(T)).ReadObject(ms);
+ }
}
}
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs
index 186f4ffe019..0b717fb2d83 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.Serialization;
using Windows.Storage;
namespace Microsoft.Toolkit.Uwp.Helpers
@@ -14,7 +15,9 @@ public class LocalObjectStorageHelper : BaseObjectStorageHelper
///
/// Initializes a new instance of the class,
/// which can read and write data using the provided ;
- /// if none is provided, a default Json serializer will be used.
+ /// if none is provided, a default Json serializer will be used (based on ).
+ /// In 6.1 and older the default Serializer was based on Newtonsoft.Json and the new default Serializer may behave differently.
+ /// To implement a based on Newtonsoft.Json or System.Text.Json see https://aka.ms/wct/storagehelper-migration
///
/// The serializer to use.
public LocalObjectStorageHelper(IObjectSerializer objectSerializer = null)
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs
index 18bd7d244ec..e2d9ae9b2b6 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.Serialization;
using Windows.Storage;
namespace Microsoft.Toolkit.Uwp.Helpers
@@ -14,7 +15,9 @@ public class RoamingObjectStorageHelper : BaseObjectStorageHelper
///
/// Initializes a new instance of the class,
/// which can read and write data using the provided ;
- /// if none is provided, a default Json serializer will be used.
+ /// if none is provided, a default Json serializer will be used (based on ).
+ /// In 6.1 and older the default Serializer was based on Newtonsoft.Json and the new default Serializer may behave differently.
+ /// To implement a based on Newtonsoft.Json or System.Text.Json see https://aka.ms/wct/storagehelper-migration
///
/// The serializer to use.
public RoamingObjectStorageHelper(IObjectSerializer objectSerializer = null)
diff --git a/Microsoft.Toolkit.Uwp/Microsoft.Toolkit.Uwp.csproj b/Microsoft.Toolkit.Uwp/Microsoft.Toolkit.Uwp.csproj
index 9ba9b97cd85..8c1a309b6c3 100644
--- a/Microsoft.Toolkit.Uwp/Microsoft.Toolkit.Uwp.csproj
+++ b/Microsoft.Toolkit.Uwp/Microsoft.Toolkit.Uwp.csproj
@@ -9,8 +9,6 @@
-
-
diff --git a/Microsoft.Toolkit.Uwp/Properties/Microsoft.Toolkit.Uwp.rd.xml b/Microsoft.Toolkit.Uwp/Properties/Microsoft.Toolkit.Uwp.rd.xml
deleted file mode 100644
index c852cb37baa..00000000000
--- a/Microsoft.Toolkit.Uwp/Properties/Microsoft.Toolkit.Uwp.rd.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs
index 0099a77ff49..53698707f70 100644
--- a/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs
+++ b/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs
@@ -34,6 +34,7 @@ public void Test_StorageHelper_LegacyIntTest()
Assert.AreEqual(input, output);
}
+ [Ignore]
[TestCategory("Helpers")]
[TestMethod]
public void Test_StorageHelper_LegacyDateTest()
@@ -53,19 +54,41 @@ public void Test_StorageHelper_LegacyDateTest()
Assert.AreEqual(input, output);
}
+ [Ignore]
[TestCategory("Helpers")]
[TestMethod]
- public void Test_StorageHelper_LegacyPersonTest()
+ public void Test_StorageHelper_LegacyInternalClassTest()
{
string key = "Contact";
- Person input = new Person() { Name = "Joe Bloggs", Age = 42 };
+ UI.Person input = new UI.Person() { Name = "Joe Bloggs", Age = 42 };
// simulate previous version by generating json and manually inserting it as string
string jsonInput = JsonSerializer.Serialize(input);
storageHelper.Save(key, jsonInput);
+ // now read it as int to valid that the change works
+ UI.Person output = storageHelper.Read(key, null);
+
+ Assert.IsNotNull(output);
+ Assert.AreEqual(input.Name, output.Name);
+ Assert.AreEqual(input.Age, output.Age);
+ }
+
+ [TestCategory("Helpers")]
+ [TestMethod]
+ public void Test_StorageHelper_LegacyPublicClassTest()
+ {
+ string key = "Contact";
+
+ UI.Person input = new UI.Person() { Name = "Joe Bloggs", Age = 42 };
+
+ // simulate previous version by generating json and manually inserting it as string
+ string jsonInput = JsonSerializer.Serialize(input);
+
+ storageHelper.Save(key, jsonInput);
+
// now read it as int to valid that the change works
Person output = storageHelper.Read(key, null);
@@ -123,5 +146,12 @@ public void Test_StorageHelper_NewPersonTest()
Assert.AreEqual(input.Name, output.Name);
Assert.AreEqual(input.Age, output.Age);
}
+
+ public class Person
+ {
+ public string Name { get; set; }
+
+ public int Age { get; set; }
+ }
}
}
diff --git a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
index 4f24302dafc..b7adf88cfc3 100644
--- a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
+++ b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
@@ -122,9 +122,6 @@
4.3.0
-
- 4.7.2
-