fix(test): Make serialization tests robust against key reordering #4990
+53
−32
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.
Description
This pull request resolves a non-deterministic behavior in the core serialization test suite, ensuring CI stability.
Problem: The test io.swagger.v3.core.serialization.properties.PropertySerializationTest can fail intermittently because the default Jackson
ObjectMapper
does not guarantee the serialization order of an object's properties. It uses Java Reflection to discover class fields, and the order in which the JVM returns these fields is not specified and can vary between runs or Java versions. This non-deterministic behavior was detected using the NonDex tool. This pull request is for a simple fix to make the test deterministic.Reference: https://tedblob.com/jackson-serialization-order/
Fixes: The existing tests used a direct
assertEquals
on the serialized string. This PR introduces a new test utility,JsonAssert
, with a static methodassertJsonEquals
. This method provides a robust, order-insensitive comparison of two JSON strings by:JsonNode
tree structure.JsonNode.equals()
, which performs a deep, semantic comparison.Note: Only
PropertySerializationTest
has been refactored to use this new assertion, making them stable and reliable while still correctly verifying the serialized output. Other tests under io.swagger.v3.core.serialization have NOT yet been refactored. They can be refactored after this PR gets reviewed and accepted.Type of Change
Checklist