It looks like you are mixing two things together.
Does the JSON parser use different primitives for integer and non-integer values?
Comparison of values is performed using the specified metric object. This match has no effect on Json Parser. No matter what value you assign to the match ( 5 in the first example) and what value will be returned by the jsonpath, the match is ( org.hamcrest.core.IsEqual ) compares both values by calling the Objects.equals () method. Json parser also works with object values, not primitives.
so how did 5 work, which is int and not double?
Assuming JsonPath lotto.lottoId will return an int value, thus body("lotto.lottoId", equalTo(5)); will be true (obviously json should be 5 )
12.2' and 12.2f' are treated as the same values in your example. The suffix 'f' in your example is redundant and has no effect. Since the closeTo(double, double) method defined argument types as double, the passed float values would get an implicit advance to double types.
Since you know that the json value will be double, you can express your statement as:
get("/price").then().body("price", closeTo(12.12, 0.01));
Depending on the configuration of the Json parser, a non-integer value may be read as BigDecimal. If so, you can use variance closeTo() as
.get("/price").then().body("price", closeTo(BigDecimal.valueOf(12.12), BigDecimal.valueOf(0.01)))
Hope this helps.
source share