fix(jbpm-workitems-rest): make test TransformerJSONandXMLTest.testJSONTransformer deterministic #2481
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.
Purpose
This PR fixes the flaky test:
org.jbpm.process.workitem.rest.TransformerJSONandXMLTest.testJSONTransformerThis test fails nondeterministically due to the non-deterministic field ordering in JSON serialization performed by Jackson’s
ObjectMapper.Why the test fails (root cause)
The test serializes a
Personobject into JSON using the expression:and asserts string equality against an expected JSON string:
{"name":"john","age":34}However, Jackson does not guarantee deterministic property ordering when serializing POJOs unless explicitly configured.
Depending on JVM and internal HashMap ordering, the serialized output can vary between:
{"name":"john","age":34}and
{"age":34,"name":"john"}Although these JSON objects are semantically equivalent, the test performs a raw string comparison, making it order-sensitive and thus flaky under randomized iteration (e.g., when using [NonDex](https://github.com/TestingResearchIllinois/NonDex)).
How to reproduce the test failure
Running the test multiple times with NonDex randomization:
Example flaky output:
Description of the fix
The fix replaces raw string comparison with semantic JSON comparison using Jackson’s
ObjectMapper:This ensures that the test compares the contents of the JSON objects rather than their textual field order.
Both maps are deserialized into standard Java maps whose equality check is order-insensitive.
Verification of the fix
nondexRuns=10) passed consistently.Key points
TransformerJSONandXMLTest.