1

@PostMapping(path = "/get-offers", consumes = LoyaltyConstant.APP_JSON) public CustomOffersResponse getLoyaltyOffers(@Context HttpServletRequest request,

@RequestBody @Valid CustomOffersTransactionRequest txnRequest, BindingResult bindingResult){
logger.info("Entering :: CustomOffersRestController method getLoyaltyOffers");

CustomOffersResponse response = new CustomOffersResponse();
try {
    if(bindingResult.hasErrors()) {
        response.setResponseCode(String.valueOf(ErrorCode.REASON_ERROR_BAD_REQUEST_CODE ));
        response.setResponseMessage(bindingResult.getFieldError().getDefaultMessage());
        return response;
    }
    CustomOffersResponse purchaseResponse = validatePurchaseItems(txnRequest.getPurchaseItems() );
    if(!purchaseResponse.getResponseCode().equals(ErrorCode.ERROR_CODE_LP000))
        return purchaseResponse;
    return customOffersRequestHandler.getOffers(txnRequest);
} catch (Exception e) {
    logger.error("Error :: CustomOffersRestController :: getLoyaltyOffers method ", e);
}
logger.info("Exiting :: CustomOffersRestController :: getLoyaltyOffers");
return response;

}

Please help out in solving the nullpointerException at getFieldError(), getFieldError() is the method ,which is present in org.springframework.validation.Error interface

  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Ken Y-N Dec 14 '20 at 08:50
  • You'll have to as a minimum provide the full text of the exception and describe what you have already tried, otherwise this will be soon closed as a duplicate, I think. – Ken Y-N Dec 14 '20 at 08:52
  • Snoar says: A “NullPointerException” could be thrown; “getFieldError()” can return null..Please help out in solving the nullpointerException at getFieldError(), getFieldError() is the method ,which is present in org.springframework.validation.Error interface , – Shoaib Ahmed Dec 14 '20 at 10:53

0 Answers0