json-iterator / java

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
http://jsoniter.com/
MIT License
1.51k stars 519 forks source link

Fix flaky tests #353

Open anirudh711 opened 10 months ago

anirudh711 commented 10 months ago

PR Overview

The PR proposes a fix for the following tests - com.jsoniter.extra.TestPreciseFloat#test_indirect_encode com.jsoniter.output.TestGson#test_serializeNulls com.jsoniter.output.TestObject#test_omit_default com.jsoniter.output.TestObject#test_omit_null com.jsoniter.output.TestNested#test_map_of_objects com.jsoniter.output.TestNested#test_object_of_array com.jsoniter.output.TestGenerics#test_wildcard com.jsoniter.output.TestObject#test_indention

Build Project

https://github.com/json-iterator/java/blob/6925cf4c19d313504b416f58a349a36bf563e0e1/src/test/java/com/jsoniter/output/TestGenerics.java#L47-L57

This means for the test above, the json that is being serilaised is -

{ field:[1] , field2:{"hello":1} }

The serialized output can be either

"{\"field\":[1],\"field2\":{\"hello\":1}}"
"{\"field2\":{\"hello\":1},\"field\":[1]}"

This change in ordering presents itself in different instances in the above eight tests.

Fix:

The proposed fix to use JSONAssert.assertEquals from org.skyscreamer.jsonassert.JSONAssert package which checks the structure of the JSON in the equality and not focus on the order of the field. This provides more granularity and accuracy of how we check JSON value equalities.