ResponseEntity<JsonNode> response = null;
//Calling POST Method
response=restTemplate.exchange(url, HttpMethod.POST,request,JsonNode.class);
restResponse.setStatusCode(response.getStatusCode());
restResponse.setHeaders(response.getHeaders());
if(response.getBody().isNull())
{
//DO SOMETHING
}
Issue: Facing Null Pointer Exception
Eventhough I am trying to handle Not Null scenario using check response.getBody().isNull() , but seems like this check also leads to null pointer exeception.
My assumptions : response.getBody() should return me JsonNode object on which I am trying to execute isNull() method.
I am not sure how this call again lead to Null Pointer Exception.
On Intellij It shows as getBody() method is @Nullable there are chances of Null pointer exception.
I searched online some solution says to use response.getBody()!=null will work. I am confused. Then what is use of isNull() method?