@Override protected <T> T createAndScheduleObject(Class<T> clz, Map<String, Object> properties) { String value = DataAccessor.fromMap(properties).withKey("value").as(String.class); if (StringUtils.isNotBlank(value)) { try { String newValue = secretsService.encrypt(ApiUtils.getPolicy().getAccountId(), value); properties.put("value", newValue); } catch (IOException e) { log.error("Failed to secret", e); throw new ClientVisibleException(ResponseCodes.SERVICE_UNAVAILABLE); } } T result = super.createAndScheduleObject(clz, properties); if (result instanceof Secret) { ((Secret) result).setValue(value); } return result; }