Skip to content
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

Fix JsonHelper.Format failing when deserializing top-level array objects #640

Merged
merged 1 commit into from
Aug 26, 2022
Merged

Fix JsonHelper.Format failing when deserializing top-level array objects #640

merged 1 commit into from
Aug 26, 2022

Conversation

rahman-ben
Copy link
Contributor

Adds appropriate test cases to JsonHelperTests

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • UI change (please include screenshot!)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Internationalization and localization
  • Other (please describe):

What is the current behavior?

Current behavior will deserialize the Input field of the JsonFormatter as a JObject, which will work as expected for top-level values and object definitions. But when the top-level object is an array, it cannot be serialized to this type, and instead writes the exception body to the Output.

Issue Number: #620

What is the new behavior?

The new behavior deserializes the Input text as a JToken, which is able to represent both JObject and JArray types. To handle sorting properties recursively, I created an overload of JsonFormatter.SortJsonPropertiesAlphabetically for JArray objects. Both methods were modified to recursively call eachother based on the property's JToken type.

Other information

image

Quality check

Before creating this PR, have you:

  • Followed the code style guideline as described in CONTRIBUTING.md
  • Verified that the change work in Release build configuration
  • Checked all unit tests pass

…cts.

Adds appropriate test cases to JsonHelperTests
Copy link
Collaborator

@veler veler left a comment

Choose a reason for hiding this comment

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

Thank you very much for this contribution! It looks great! :D

@veler veler merged commit e9b2598 into DevToys-app:main Aug 26, 2022
@rahman-ben rahman-ben deleted the fix-jsonhelper-top-level-array-parse branch August 27, 2022 06:50
@veler veler linked an issue Aug 31, 2022 that may be closed by this pull request
veler pushed a commit that referenced this pull request Mar 31, 2023
…cts. (#640)

Adds appropriate test cases to JsonHelperTests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants