I have two JSON objects represented as Java Strings
Expected:
{
"id" : "1234567"
"balance" : "123"
}
I converted this into JSON object and trying to validate this with output JSON Actual:
{
"id" : "1234567"
"balance" : "123.00"
}
I am using JSONAssert.assertequal("incorrect json",actual,expected,false);
This is failing with expected 123 and got 123.00.
what to do so that it will treat both the values same.in a nutshell how do I use custom comaparator ,please note that I dont want to exclude/suppress this attribute from my validation
The balance field in the Java class should be defined as an int (or float), not a String.
If applicable, it should be defined as a “number” in any JsonSchema, swagger or open-api definition.
The ‘expected’ can be defined as either of the following and the
JSONAssert.assertEqualswill work without a custom comparator - see Introduction to JSONassert section 3.4 Logical Camparison:or
If you do not have control of the field types then a comparator for the balance field would look like this: