Source:
public ResponseEntity saveOrUpdate(@RequestParam Long applicationId, @Valid @RequestBody StateHistoryViewRepresentation stateHistoryViewRepresentation, BindingResult bindingResult, Locale locale) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT_CONSTANT); StateHistoryDTO stateHistoryDTO = null; if (bindingResult.hasErrors()) { String invalidInputMessage = messageSource.getMessage(COMMON_INVALID_INPUT_MESSAGE_KEY, null, locale); RestResponse restResponse = new RestResponse(invalidInputMessage); bindingResult.getFieldErrors().forEach(error -> { restResponse.addField(error.getField(), messageSource.getMessage(error.getDefaultMessage(), new Object[0], locale)); }); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } else { try { stateHistoryDTO = StateHistoryDTO.builder() .id(stateHistoryViewRepresentation.getId()) .candidateId(stateHistoryViewRepresentation.getCandidateId()) .languageSkill(stateHistoryViewRepresentation.getLanguageSkill()) .description(stateHistoryViewRepresentation.getDescription()) .result(stateHistoryViewRepresentation.getResult()) .offeredMoney(stateHistoryViewRepresentation.getOfferedMoney()) .claim(stateHistoryViewRepresentation.getClaim()) .feedbackDate(stateHistoryViewRepresentation.getFeedbackDate() != null && !stateHistoryViewRepresentation.getFeedbackDate().isEmpty() ? simpleDateFormat .parse(stateHistoryViewRepresentation.getFeedbackDate()) : null) .dayOfStart(stateHistoryViewRepresentation.getDayOfStart() != null && !stateHistoryViewRepresentation.getDayOfStart().isEmpty() ? simpleDateFormat .parse(stateHistoryViewRepresentation.getDayOfStart()) : null) .creationDate(stateHistoryViewRepresentation.getCreationDate() != null && !stateHistoryViewRepresentation.getCreationDate().isEmpty() ? simpleDateFormat .parse(stateHistoryViewRepresentation.getCreationDate()) : null) .stateDTO(StateDTO.builder().id(stateHistoryViewRepresentation.getStateId()) .name(stateHistoryViewRepresentation.getStateName()).build()) .build(); } catch (ParseException e) { e.printStackTrace(); } statesHistoryService.saveStateHistory(stateHistoryDTO, applicationId); return new ResponseEntity<>(Collections.singletonMap("applicationId", applicationId), HttpStatus.OK); } }

Target:
public ResponseEntity saveOrUpdate(@RequestParam Long applicationId, @Valid @RequestBody StateHistoryViewRepresentation stateHistoryViewRepresentation, BindingResult bindingResult, Locale locale) { StateHistoryDTO stateHistoryDTO = null; if (bindingResult.hasErrors()) { return fieldErrorResponseComposer.composeResponse(bindingResult); } else { try { stateHistoryDTO = StateHistoryDTO.builder() .id(stateHistoryViewRepresentation.getId()) .candidateId(stateHistoryViewRepresentation.getCandidateId()) .languageSkill(stateHistoryViewRepresentation.getLanguageSkill()) .description(stateHistoryViewRepresentation.getDescription()) .result(stateHistoryViewRepresentation.getResult()) .offeredMoney(stateHistoryViewRepresentation.getOfferedMoney()) .claim(stateHistoryViewRepresentation.getClaim()) .feedbackDate(stateHistoryViewRepresentation.getFeedbackDate() != null && !stateHistoryViewRepresentation.getFeedbackDate().isEmpty() ? DATE_FORMAT .parse(stateHistoryViewRepresentation.getFeedbackDate()) : null) .dayOfStart(stateHistoryViewRepresentation.getDayOfStart() != null && !stateHistoryViewRepresentation.getDayOfStart().isEmpty() ? DATE_FORMAT .parse(stateHistoryViewRepresentation.getDayOfStart()) : null) .creationDate(stateHistoryViewRepresentation.getCreationDate() != null && !stateHistoryViewRepresentation.getCreationDate().isEmpty() ? DATE_FORMAT .parse(stateHistoryViewRepresentation.getCreationDate()) : null) .stateDTO(StateDTO.builder().id(stateHistoryViewRepresentation.getStateId()) .name(stateHistoryViewRepresentation.getStateName()).build()) .build(); } catch (ParseException e) { RestResponse restResponse = new RestResponse(e.getMessage()); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } statesHistoryService.saveStateHistory(stateHistoryDTO, applicationId); return new ResponseEntity<>(Collections.singletonMap("applicationId", applicationId), HttpStatus.OK); } }