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

deterministically serialize number and string JSON output #2527

Merged
merged 1 commit into from Feb 5, 2021

Conversation

dieterv
Copy link
Contributor

@dieterv dieterv commented Jan 10, 2021

Description

Deterministically serialize number and string JSON output.

Related Issue

Fixes #1688 and fixes #2304.

Motivation and Context

Ever since the introduction of the JsonOutputFormatter way back
in 2014 [1] all fields where serialized as JSON string. Except
for values looking like an int which where then serialized as JSON
numbers. This had some strange unpredictable side effects like
PreReleaseNumber being an empty JSON string instead of null
or a "2009069" ShortSha being formatted as a JSON number.

This change ensures all fields are serialized as JSON string
except Major, Minor, Patch, PreReleaseNumber,
WeightedPreReleaseNumber, CommitsSinceVersionSource and
UncommittedChanges which are now always serialized as JSON number.

Deserialisation remains the same as before for all fields so we
continue to accept both JSON string and JSON number formatted
values.

[1] f2daf60#diff-fde1a8ff593c6ac2ad558a6f9bb512e0350db91343b185f9b2a00d1d6e848bc3

How Has This Been Tested?

Checklist:

  • My code follows the code style of this project.
  • My change dos not require a change to the documentation (https://gitversion.net/docs/more-info/variables remains correct).
  • There was no need to update the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

While I think this is a change for the better, it may be viewed as a breaking change, even though it can be argued that the existing behavior is a bug. I'm not entirely sure what to do with it. Thoughts?

src/GitVersionCore/Model/VersionVariables.cs Outdated Show resolved Hide resolved
src/GitVersionCore/Model/VersionVariables.cs Outdated Show resolved Hide resolved
src/GitVersionCore/Model/VersionVariables.cs Outdated Show resolved Hide resolved
src/GitVersionCore/Model/VersionVariables.cs Outdated Show resolved Hide resolved
@dieterv dieterv force-pushed the feature/jsonserializer branch 3 times, most recently from 883d4af to bc0f79c Compare January 17, 2021 20:12
Base automatically changed from master to main January 31, 2021 12:46
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

I think the change from "" to null is an acceptable compromise and not enough of a breaking change to warrant a major version bump. I therefore give this 👍🏼. Great work! Please just rebase your changes on HEAD of main so we get rid of the merge conflicts and this is good to go.

Ever since the introduction of the JsonOutputFormatter way back
in 2014 [1] all fields where serialized as JSON string. Except
for values looking like an int which where then serialized as JSON
numbers. This had some strange unpredictable side effects like
PreReleaseNumber being an empty JSON string instead of null
or a "2009069" ShortSha being formatted as a JSON number.

This change ensures all fields are serialized as JSON string
except Major, Minor, Patch, PreReleaseNumber,
WeightedPreReleaseNumber, CommitsSinceVersionSource and
UncommittedChanges which are now always serialized as JSON number.

Deserialisation remains the same as before for all fields so we
continue to accept both JSON string and JSON number formatted
values.

Fixes GitTools#1688 and fixes GitTools#2304.

[1] GitTools@f2daf60#diff-fde1a8ff593c6ac2ad558a6f9bb512e0350db91343b185f9b2a00d1d6e848bc3
@dieterv
Copy link
Contributor Author

dieterv commented Feb 5, 2021

@asbjornu wrote:

Please just rebase your changes on HEAD of main so we get rid of the merge conflicts and this is good to go.

Thanks you for taking the time to review this! Rebased as requested 😃

@asbjornu asbjornu added this to the 5.6.5 milestone Feb 5, 2021
@arturcic arturcic self-requested a review February 5, 2021 08:57
@arturcic arturcic merged commit 6d2ff62 into GitTools:main Feb 5, 2021
@arturcic
Copy link
Member

arturcic commented Feb 5, 2021

@dieterv thank you so much for your contributions 👍

@dieterv dieterv deleted the feature/jsonserializer branch February 5, 2021 09:14
@dieterv
Copy link
Contributor Author

dieterv commented Feb 5, 2021

Thank you @arturcic 😀

@github-actions
Copy link

github-actions bot commented Feb 7, 2021

🎉 This issue has been resolved in version 5.6.5 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants