Change JSON serialization unit tests to deterministic implementation #1547
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Hello, this is a direct follow-up to my previous PR: #1546 . These tests all may be nondeterministic due to the same reason, which is JSON parameter ordering not guaranteed by Jackson's default ObjectMapper.
Again, these tests were detected via the Nondex tool, which flags Java tests that are potentially nondeterministic due to underlying assumptions regarding the Java API. In total, 11 tests were flagged (10 fixed here, 1 fixed in the previous PR):
Potential Fix
As detailed in the other PR's description, the fix I implemented is to explicitly configure the ObjectMapper to sort the JSON parameters alphabetically during serialization. Then, I manually sort the parameters of the expected JSON strings. The tests still pass (verified with
mvn clean test), and Nondex also shows a passing result now.I know this seems like quite a large PR, but I'm just applying the same approach 10 times. Please let me know regarding feedback or questions. Thank you!