Skip to content

Instantly share code, notes, and snippets.

@belgoros
Created April 17, 2023 14:38
Show Gist options
  • Save belgoros/17bdfc20f78c84fb8d087e4fb5424c08 to your computer and use it in GitHub Desktop.
Save belgoros/17bdfc20f78c84fb8d087e4fb5424c08 to your computer and use it in GitHub Desktop.
Ignore specific node values when using `JSONAssert.assertEquals`
@Test
public void testJsonArrayValues() throws JSONException {
String expectedJson = """
{
"messageElements": {
"messageStatus": "SUCCESS",
"businessCorrelationId": "a80337639eb40758",
"errorList": []
},
"data": [
{
"referenceId": 2,
"effectiveStartDate": "2021-01-08T00:00:00"
},
{
"referenceId": 2,
"effectiveStartDate": "2021-01-08T00:00:00"
}
]
}
""";
String actualJson = """
{
"messageElements": {
"messageStatus": "SUCCESS",
"businessCorrelationId": "99999",
"errorList": []
},
"data": [
{
"referenceId": 2,
"effectiveStartDate": "2021-12-08T00:00:00"
},
{
"referenceId": 2,
"effectiveStartDate": "2021-12-08T00:00:00"
}
]
}
""";
JSONAssert.assertEquals(expectedJson, actualJson, new CustomComparator(JSONCompareMode.LENIENT,
new Customization("data[*].effectiveStartDate", (ct1, ct2) -> true),
new Customization("messageElements.businessCorrelationId", (c1, c2) -> true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment