@Override
    public ValidationResult toValidationResult(String responseBody) {
        ValidationResult validationResult = new ValidationResult();
        ArrayList<String> exceptions = new ArrayList<>();
        try {
            Map result = (Map) GSON.fromJson(responseBody, Object.class);
            if (result == null) return validationResult;
            final Map<String, Object> errors = (Map<String, Object>) result.get("errors");
            if (errors != null) {
                for (Map.Entry<String, Object> entry : errors.entrySet()) {
                    if (!(entry.getValue() instanceof String)) {
                        exceptions.add(String.format("Key: '%s' - The Json for Validation Request must contain a not-null error message of type String", entry.getKey()));
                    } else {
                        validationResult.addError(new ValidationError(entry.getKey(), entry.getValue().toString()));
                    }
                }
            }
            if (!exceptions.isEmpty()) {
                throw new RuntimeException(StringUtils.join(exceptions, ", "));
            }
            return validationResult;
        } catch (Exception e) {
            LOGGER.error("Error occurred while converting the Json to Validation Result. Error: {}. The Json received was '{}'.", e.getMessage(), responseBody);
            throw new RuntimeException(String.format("Error occurred while converting the Json to Validation Result. Error: %s.", e.getMessage()));
        }
    }
@Test
    public void shouldConvertJsonResponseToValidationResultWhenValidationFails() {
        String jsonResponse = "{\"errors\":{\"key1\":\"err1\",\"key2\":\"err2\"}}";

        TaskConfig configuration = new TaskConfig();
        TaskConfigProperty property = new TaskConfigProperty("URL", "http://foo");
        property.with(Property.SECURE, false);
        property.with(Property.REQUIRED, true);
        configuration.add(property);

        ValidationResult result = new JsonBasedTaskExtensionHandler_V1().toValidationResult(jsonResponse);

       assertThat(result.isSuccessful(), is(false));


        ValidationError error1 = result.getErrors().get(0);
        ValidationError error2 = result.getErrors().get(1);

       assertThat(error1.getKey(), is("key1"));
       assertThat(error1.getMessage(), is("err1"));
       assertThat(error2.getKey(), is("key2"));
       assertThat(error2.getMessage(), is("err2"));
    }