Scenario:
There is a method in a API response object which concatenates two fields. Say getFullName() which returns name in the format "lastname, firstname". This object is returned like below from the REST controller endpoint method.
@PostMapping(consumes = {"application/json"}, produces = {"application/json"})
public ResponseEntity<User> createUser(@RequestBody User payload) throws Exception {
User data = userService.createUser(payload);
return ResponseEntity.created(URI.create(data.getId())).body(data);
}
Unfortunately if there is an exception in this method, for example a NPE, it is neither getting logged nor generating the response with exception message. Instead the spring is returning a 500 error with boiler plate "Internal Server Error" html (given below). It was very difficult to figure out the error line since there was no stacktrace being printed even while debugging.
On further research, I found that the exception is from com.fasterxml.jackson.databind.ser.std. BeanSerializerBase due to a NPE from the getter method (fixed the same). However, I am wondering why this is not getting logged or printing the stacktrace in debug console?