public ResponseEntity constraintException(ConstraintViolationException exception) { ApiErrorDTO apiErrorDTO = new ApiErrorDTO(); apiErrorDTO.setMessage(exception.getMessage()); apiErrorDTO.setTimestamp(new Date().getTime()); apiErrorDTO.setCode(exception.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .header("Content-Type", "application/json; charset=utf-8") .body(apiErrorDTO); }