So for the fix.
This is where I am getting an NPE initially when my conditional flow below executes.
if (getCreditCardResponseJson.getEnvelop().getBody().getResponse().getDetails().getReturnCde()
.equals(CreditCardStatus.VALID_CARD.getCode()))
In the debug logs, I could see that it is getting a null value from the getReturnCde code.
Hence I assumed that just assigning a default value on it when it throws a null would be fine, apparently, I also need to assign or set its value from the higher level class where this model is being retrieved as that model class also has a null value.
So instead of doing the above code I asked in the question, I did it on the higher class with the first null thrown at first.
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
public final class GetCreditCardInfo {
@JsonAlias("ns:return")
private CreditCardDetails details;
@SuppressWarnings("checkstyle:RegexpSingleline")
public CreditCardDetails getDetails() {
if (details == null) {
final CreditCardDetails creditCardDetails = new CreditCardDetails();
creditCardDetails.setReturnCde("01");
return creditCardDetails;
}
return details;
}
}
The code above is the class where the json payload is being serialized and assigned to JAVA POJOs. And this is is the higher level class where the **.getReturnCde() is being set.
In summary, I assumed the fixed on NPE would be at CreditCardDetails class
but apparently it is not.
As I have to set the null value from the higher level model class named GetCreditCardInfo which also calls the CreditCardDetails class which also happens to throw a null value.
So in my case, I have two model classes that throws a null named GetCreditCardInfo and CreditCardDetails. My initial fix only fixed the issue CreditCardDetails and hence it is still throwing an NPE, the fix is to address the initial null thrown from the higher level class named GetCreditCardInfo as pointed by @Hulk in the comments here. So thanks. My problem is now fixed.