Source:
<code>private ExternalMetadata storeExtraFieldsInMetaData(TelephoneChargeCreateRequest telephoneChargeRequest) { HashMap<String, Object> telephoneJSON = new HashMap<>(); telephoneJSON.put("processor_id", telephoneChargeRequest.getProcessorId().substring(0, Math.min(telephoneChargeRequest.getProcessorId().length(), 50))); telephoneJSON.put("status", telephoneChargeRequest.getPaymentOutcome().getStatus()); telephoneChargeRequest.getCreatedDate().ifPresent(createdDate -> telephoneJSON.put("created_date", createdDate.substring(0, Math.min(createdDate.length(), 50)))); <START> telephoneChargeRequest.getAuthorisedDate().ifPresent(authorisedDate -> telephoneJSON.put("authorised_date", authorisedDate.substring(0, Math.min(authorisedDate.length(), 50)))); <END> telephoneChargeRequest.getAuthCode().ifPresent(authCode -> telephoneJSON.put("auth_code", authCode.substring(0, Math.min(authCode.length(), 50)))); telephoneChargeRequest.getTelephoneNumber().ifPresent(telephoneNumber -> telephoneJSON.put("telephone_number", telephoneNumber.substring(0, Math.min(telephoneNumber.length(), 50)))); telephoneChargeRequest.getPaymentOutcome().getCode().ifPresent(code -> telephoneJSON.put("code", code.substring(0, Math.min(code.length(), 50)))); telephoneChargeRequest.getPaymentOutcome().getSupplemental().ifPresent( supplemental -> { supplemental.getErrorCode().ifPresent(errorCode -> telephoneJSON.put("error_code", errorCode.substring(0, Math.min(errorCode.length(), 50)))); supplemental.getErrorMessage().ifPresent(errorMessage -> { if(errorMessage.length() > 50) { logger.info(String.format("Telephone payment message for charge_processor_id of " + telephoneChargeRequest.getProcessorId()+ " is longer than 50 characters and has been truncated and stored. The full message is: " + errorMessage)); } telephoneJSON.put("error_message", errorMessage.substring(0, Math.min(errorMessage.length(), 50))); }); } ); return new ExternalMetadata(telephoneJSON); }</code><technical_language>truncate createdDate, authorisedDate , errorCode. validated is exceed 50 chars</technical_language>

Target:
private ExternalMetadata storeExtraFieldsInMetaData(TelephoneChargeCreateRequest telephoneChargeRequest) { HashMap<String, Object> telephoneJSON = new HashMap<>(); String processorId = telephoneChargeRequest.getProcessorId(); telephoneJSON.put("processor_id", checkAndGetTruncatedValue(processorId, "processor_id", processorId)); telephoneJSON.put("status", telephoneChargeRequest.getPaymentOutcome().getStatus()); telephoneChargeRequest.getCreatedDate().ifPresent(createdDate -> telephoneJSON.put("created_date", createdDate)); telephoneChargeRequest.getAuthorisedDate().ifPresent(authorisedDate -> telephoneJSON.put("authorised_date", authorisedDate)); telephoneChargeRequest.getAuthCode().ifPresent(authCode -> telephoneJSON.put("auth_code", checkAndGetTruncatedValue(processorId, "auth_code", authCode))); telephoneChargeRequest.getTelephoneNumber().ifPresent(telephoneNumber -> telephoneJSON.put("telephone_number", checkAndGetTruncatedValue(processorId, "telephone_number", telephoneNumber))); telephoneChargeRequest.getPaymentOutcome().getCode().ifPresent(code -> telephoneJSON.put("code", code)); telephoneChargeRequest.getPaymentOutcome().getSupplemental().ifPresent( supplemental -> { supplemental.getErrorCode().ifPresent(errorCode -> telephoneJSON.put("error_code", checkAndGetTruncatedValue(processorId, "error_code", errorCode))); supplemental.getErrorMessage().ifPresent(errorMessage -> telephoneJSON.put("error_message", checkAndGetTruncatedValue(processorId, "error_message", errorMessage))); } ); return new ExternalMetadata(telephoneJSON); }