Skip to content

Replace JsonSerializer with DataContractJsonSerializer in Microsoft.Toolkit.Uwp. #3637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
9 commits merged into from
Jan 6, 2021
Merged

Replace JsonSerializer with DataContractJsonSerializer in Microsoft.Toolkit.Uwp. #3637

9 commits merged into from
Jan 6, 2021

Conversation

Rosuavio
Copy link
Contributor

Fixes #3636

Change implementation of JsonObjectSerializer to use DataContractJsonSerializer

PR Type

What kind of change does this PR introduce?

What is the current behavior?

Microsoft.Toolkit.Uwp uses JsonSerializer

What is the new behavior?

Microsoft.Toolkit.Uwp uses DataContractJsonSerializer

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

@ghost
Copy link

ghost commented Dec 17, 2020

Thanks RosarioPulella for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@michael-hawker
Copy link
Member

Awesome, that seems pretty straight-forward. Have you tested the update scenario for SystemInformation yet where if an app was initialized with a Newtonsoft serializer and then switches to this one all the data loads and is re-saved properly? I think that's the biggest thing for us to validate.

Outside of that it's just release notes and documentation. Adding the 'breaking changes' label here for tracking when we write the release notes as this could cause changes for developers that are doing more complex scenarios (but we have mitigation).

FYI @vgromfeld @simop-msft

@michael-hawker michael-hawker added this to the 7.0 milestone Dec 17, 2020
@ghost ghost added the in progress 🚧 label Dec 17, 2020
@michael-hawker
Copy link
Member

@RosarioPulella CI failed - looks like some tests need updating? (Or maybe a sign that we broke something?)

@Rosuavio
Copy link
Contributor Author

Have you tested the update scenario for SystemInformation yet where if an app was initialized with a Newtonsoft serializer and then switches to this one all the data loads and is re-saved properly? I think that's the biggest thing for us to validate.

I am not sure how to initialize an app using the old version of the lib in a unit test with the new lib also included in the same proj. I am looking into including the old package Microsoft.Toolkit.Uwp ver 6.1.1 using something like this maybe https://stackoverflow.com/questions/42715564/using-2-different-versions-of-the-same-dll/49238410?

@Rosuavio
Copy link
Contributor Author

Rosuavio commented Dec 23, 2020

It seems like I would have to build and run an app with 6.1.1 then build and run with the local project ref to Microsoft.Toolkit.Uwp inside the unit test... Looking into it.

@vgromfeld
Copy link
Contributor

Is there any impact on the final binary size ?
It shouldn't if the SystemInformation class is not used.

@michael-hawker
Copy link
Member

Is there any impact on the final binary size ?
It shouldn't if the SystemInformation class is not used.

@vgromfeld we were still seeing the dlls included in the SmokeTest apps and report?

Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely want to ensure we document these changes. But I think as we said as long we've tested SystemInformation we can always guide developers to use the previous Newtonsoft or System.Text.Json for compatibility.

@ghost
Copy link

ghost commented Jan 5, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Rosuavio and others added 3 commits January 5, 2021 16:53
…elper.cs

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>
…Helper.cs

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>
…geHelper.cs

Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>
@Rosuavio Rosuavio added for-review 📖 To evaluate and validate the Issues or PR reviewers wanted ✋ and removed in progress 🚧 labels Jan 5, 2021
@michael-hawker
Copy link
Member

@msftbot merge when @vgromfeld approves

@ghost
Copy link

ghost commented Jan 6, 2021

Hello @michael-hawker!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I'll only merge this pull request if it's approved by @vgromfeld

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@@ -47,6 +47,7 @@

<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />

@ghost ghost merged commit b4f1b2f into CommunityToolkit:master Jan 6, 2021
@Rosuavio Rosuavio mentioned this pull request Jan 6, 2021
@Rosuavio Rosuavio deleted the remove-textjson branch January 6, 2021 16:34
ghost pushed a commit that referenced this pull request Jan 6, 2021
ghost pushed a commit that referenced this pull request Jan 28, 2021
## Fixes #3692
This introduces a new light-weight serializer which we can use within the toolkit for the `SystemInformation` class still. And then developers with more complex type needs can specify their own serializer for the `BaseObjectStorageHelper` classes. See the related issue for more details.

Follow-on to #3637 and #3414

## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

<!-- - Bugfix -->
- Feature
<!-- - Code style update (formatting) -->
- Refactoring (no functional changes, no api changes)
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
Using `DataContractJsonSerializer`, though we had used `Newtonsoft.Json` in 6.1.

## What is the new behavior?
Use new `SystemSerializer` which passes values to/from the Windows `ApplicationDataContainer` APIs directly. Updates our internal usages of this to the new system. Requires developer using the `BaseObjectStorageHelper` to provide a serializer implementation.

This of course does provide a 'default'/system information within the toolkit now compared to our original thought of providing none at all before the `SystemInformation` problem was identified.

## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
    - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [ ] Contains **NO** breaking changes

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. 
     Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. -->

## Other information
I tested copying the system.dat file from the Settings folder of our 6.1 sample app to the development version with the changes, no issues with `SystemInformation` reading the old data.

Updated/added unit tests to test the old json layer vs. reading from the new SystemSerializer as well as just testing a new `System.Text.Json` complex scenario. Added tests for exceptions.

TODO:
- [ ] Add more tests?
- [x] Run XAML Islands SystemInformation test
- [ ] Do we want `SystemSerializer` to handle a few more 'basic' (but non-primitive) types? E.g. @Sergio0694 has a [similar implementation for a different related system](https://github.com/Sergio0694/Brainf_ckSharp/blob/master/src/Brainf_ckSharp.Services.Uwp/SettingsService.cs)
- [ ] ???
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove System.Text.Json reference in Microsoft.Toolkit.Uwp package
4 participants