Skip to content

Migrate from Newtonsoft.Json to System.Text.Json #9881

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
merged 7 commits into from
Sep 12, 2022

Conversation

ferrariofilippo
Copy link
Contributor

Resolved / Related Issues

Details of Changes

  • Removed all Newtonsoft.Json references and replaced with System.Text.Json equivalent
  • Created JSON converter for types as System.Text.Json doesn't support TypeBinding

Validation

  • Built and ran the app

Copy link
Member

@hez2010 hez2010 left a comment

Choose a reason for hiding this comment

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

I've left some suggestions.
Thanks for your contribution.

@hez2010 hez2010 added the changes requested Changes are needed for this pull request label Sep 2, 2022
@yaira2 yaira2 added needs - code review and removed changes requested Changes are needed for this pull request labels Sep 2, 2022
hez2010
hez2010 previously approved these changes Sep 3, 2022
Copy link
Member

@hez2010 hez2010 left a comment

Choose a reason for hiding this comment

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

LGTM.

@hez2010
Copy link
Member

hez2010 commented Sep 3, 2022

Ignore my last approve. Seems that S.T.J will deserialize json to Dictionary<string, JsonElement> if the target type is Dictionary<string, object>, so that the property value cannot be directly accessed with an indexer.

@hez2010 hez2010 dismissed their stale review September 3, 2022 10:23

Doesn't work.

@yaira2 yaira2 requested a review from hez2010 September 4, 2022 22:21
@hez2010
Copy link
Member

hez2010 commented Sep 12, 2022

@ferrariofilippo Can you resolve the merge conflicts?

Copy link
Member

@yaira2 yaira2 left a comment

Choose a reason for hiding this comment

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

LGTM

@yaira2 yaira2 merged commit 714a48d into files-community:main Sep 12, 2022
@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels Sep 12, 2022
@ferrariofilippo ferrariofilippo deleted the Feature_#9793 branch September 12, 2022 19:31
@yaira2 yaira2 changed the title Migrate from Newtonsoft.Json to System.Text.Json #9873 Migrate from Newtonsoft.Json to System.Text.Json Sep 14, 2022
AppCenter.Start((string)obj.SelectToken("key"), typeof(Analytics), typeof(Crashes));
using var document = System.Text.Json.JsonDocument.Parse(lines);
var obj = document.RootElement;
AppCenter.Start(obj.GetPropertyValue<string>("key"), typeof(Analytics), typeof(Crashes));
Copy link
Member

Choose a reason for hiding this comment

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

It appears that this isn't reading the json file correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That exception was thrown even by Newtonsoft.Json because that file is empty

Copy link
Member

Choose a reason for hiding this comment

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

You can test by adding data and seeing that it doesn't work (pipeline adds data when the app is built)

Copy link
Contributor Author

@ferrariofilippo ferrariofilippo Sep 15, 2022

Choose a reason for hiding this comment

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

This should fix the problem
AppCenter.Start(obj.GetProperty("key").GetString(), typeof(Analytics), typeof(Crashes));
Should I open a new PR?


You can also remove using Vanara.Extensions.Reflection; as is no longer needed

Copy link
Member

Choose a reason for hiding this comment

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

Should I open a new PR?

Please 👍
Can do the same for the bing api key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Migrate from Newtonsoft.Json to System.Text.Json
3 participants