I have faced the same problem recently and just transitioned all our tests (which expect JSON attributes to be in the same order) to another JSON library:
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.5</version>
</dependency>
Internally it uses a LinkedHashMap
, which maintains the order of attributes. This library is functionally equivalent to the json.org
library, so I don't see any reason why not use it instead, at least for tests.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…