Open ravichandrasurabhi opened 6 years ago
The JSON requests and responses are controlled by the library that reads and writes them. Generally, the keys will be in alphabetical order.
Yes, can't we make it in specific format ?
For anyone who finds this issue: I also came up against this when upgrading to the lastest version of pact-jvm. It's because of this line: https://github.com/pact-foundation/pact-jvm/blob/c91f44d2a523240b69899d2c705937ae9cbb5448/core/support/src/main/kotlin/au/com/dius/pact/core/support/json/JsonValue.kt#L96 that when the pact retrieved from the broker is serialised to a JSON string in order to be sent to the provider under test, that the keys appear in alphabetical order, not in the order in the pact shown in the broker.
I think this makes sense and the fact that a pact requires keys to be in a certain order is probably an indication that the contract is wrong and/or is being too strict.
The keys are sorted in the pact file to ensure the file does not change if just the order of keys changes. Otherwise the pact broker will treat it as a different pact file.
I don't think it is good to have tests that are dependent on key order. You should be testing for the presence of values, not that "date" comes before "bill".
For Example:
There are ORDER_NUMBER , BILL, DATE. As per PACT its generating according to alphabetical order. To see its not looking good as we need Order Number First.
I need response like this exactly
{
"orderNumber": "S123", "date": "2000-01-31", "bill: "08717" }
But in PACT file it is like
{
"bill: "08717", "date": "2000-01-31", "orderNumber": "S123"
}
Is there any way to resolve this ?