Given the following JSON:
{
"priceOne": 1034,
"priceTwo": null,
"priceThree": 7282,
}
...and the following Rest Assured method to get the priceTwo
value and set to a specific value:
public void getPrice() {
setPriceService();
Response response =
given().
spec(priceServiceRequestSpec)
when().
get("api/v1/prices/102934").
then().extract().response();
if (StringUtils.isNotEmpty(response.path("priceTwo").toString())) {
vehicle.setPrice(response.path("priceTwo").toString());
return true;
} else {
vehicle.setPrice("2000");
}
}
...I am getting a NullPointerException when I expect the
StringUtils.isNotEmpty
to handle this. I expect this is down to the way I am using the response.path
as a paramater. What is a better way of achieving this?