I need to compare two json strings by ignore some fields
I am currently using JSONAssert from org.SkyScreamer to do the comparison but does not ignore any attributes.
Json 1 :
{
"contributions": [
[
{
"order" : 1,
"contributorId" : "1980"
}
]
]
}
Json 2 :
{
"contributions": [
[
{
"order": 1,
"contributorId" : "5789"
}
]
]
}
ArrayValueMatcher<Object> arrValMatch1 = new ArrayValueMatcher<>(new CustomComparator(
JSONCompareMode.NON_EXTENSIBLE,
new Customization("contributions[0][*].contributorId",(o1, o2) -> true)));
Customization arrayValueMatchCustomization = new Customization("contributions", arrValMatch1);
CustomComparator customArrayValueComparator = new CustomComparator(
JSONCompareMode.NON_EXTENSIBLE,
arrayValueMatchCustomization);
assertEquals(subJson1, json2, customArrayValueComparator);
I expect the above scenario should be passed. But its failing with
Exception in thread "main" java.lang.AssertionError: contributions[0][contributorId=1980]
Expected: a JSON object
but none found
; contributions[0][contributorId=5789]
Unexpected: a JSON object