Skip to content

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

@michael-hawker

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions