Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Remove System.Text.Json reference in Microsoft.Toolkit.Uwp package #3636

Closed

Description

@michael-hawker

Describe the bug

We're only using this dependency (which is large) for a single helper in the package. We should streamline this with some docs instead of having a hard dependency. This also makes it easier for folks to use either Newtonsoft.Json or System.Text.Json depending on what their app is already using.

Add docs for:

using System.Text.Json;

namespace Microsoft.Toolkit.Uwp.Helpers
{
    public class JsonObjectSerializer : IObjectSerializer
    {
        public string Serialize<T>(T value) => JsonSerializer.Serialize(value);

        public T Deserialize<T>(string value) => JsonSerializer.Deserialize<T>(value);
    }
}
using Newtonsoft.Json;

namespace Microsoft.Toolkit.Uwp.Helpers
{
    internal class JsonObjectSerializer : IObjectSerializer
    {
        public string Serialize<T>(T value) => JsonConvert.SerializeObject(value);

        public T Deserialize<T>(string value) => JsonConvert.DeserializeObject<T>(value);
    }
}

Instead of including explicitly. This will help with #3145 as most other higher-level toolkit libs are including the UI package which also includes this package.

FYI @vgromfeld @simop-msft

Activity

  1. added this to the 7.0 milestone on Dec 17, 2020
  2. michael-hawker commented on Dec 17, 2020

    @michael-hawker
    MemberAuthor

    Snafu... the SystemInformation helpers use the LocalObjectStorageHelper which uses this...

    Instead of completely requiring the developer to specify the serialization option, do we want to provide a base implementation which uses DataContractJsonSerializer instead? This would basically complete the original #889 issue.

    At least for the SystemInformation class, I believe that would be simple enough in terms of data structure to be able to directly read-in any existing uses from apps.

    ⚠ Since 6.1 shipped with the Newtonsoft Serializer, for testing of the final change, we should make sure we try having a contract serializer with Newtonsoft initialize the SystemInformation storage on the app. Then change to the new serializer and ensure it can read-in all the data to continue from for app migrations.

    For more complex app scenarios where devs have done more complex storage, the recommendation is that they provide their own storage helper (as noted above in the issue) for either Newtonsoft or System.Text.Json as they desire.

  3. ghost closed this as completedin #3637on Jan 6, 2021
  4. ghost added a commit that references this issue on Jan 6, 2021
    b4f1b2f
  5. michael-hawker commented on Jan 6, 2021

    @michael-hawker
    MemberAuthor

    Before:

    Microsoft.Toolkit.Uwp Additional Footprint: 635,580 bytes
      App Diff: (.exe) = 4,096
      App Diff: (.xml) = 264
      App Diff: (.appxsym) = 40,009
      Size Diff: AppxBundleManifest.xml = 11
      Size Diff: AppxBlockMap.xml = 1,190
      Size Diff: AppxManifest.xml = 10
      Size Diff: resources.pri = 104
      Size Diff: System.Runtime.CompilerServices.Unsafe.dll = 1,744
      Additional: Microsoft.Bcl.AsyncInterfaces.dll = 21,064
      Additional: Microsoft.Toolkit.dll = 103,456
      Lib (self): Microsoft.Toolkit.Uwp.dll = 112,672
      Additional: System.Text.Encodings.Web.dll = 57,720
      Additional: System.Text.Json.dll = 293,240
    -----------------------------------------
    

    And After (Projected due to #3657):

    Microsoft.Toolkit.Uwp Additional Footprint: 263,556 bytes
      App Diff: (.exe) = 4,096
      App Diff: (.xml) = 264
      App Diff: (.appxsym) = 40,009
      Size Diff: AppxBundleManifest.xml = 11
      Size Diff: AppxBlockMap.xml = 1,190
      Size Diff: AppxManifest.xml = 10
      Size Diff: resources.pri = 104
      Size Diff: System.Runtime.CompilerServices.Unsafe.dll = 1,744
      Additional: Microsoft.Toolkit.dll = 103,456
      Lib (self): Microsoft.Toolkit.Uwp.dll = 112,672
    -----------------------------------------
    

    Savings of: 372,024 🎉🎉🎉

    And since most of our other higher-level packages reference this base package, we'll save this amount on those too!

  6. ghost locked as resolved and limited conversation to collaborators on Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions