@Override
    public TaskConfig convertJsonToTaskConfig(String configJson) {
        final TaskConfig taskConfig = new TaskConfig();
        ArrayList<String> exceptions = new ArrayList<>();
        try {
            Map<String, Object> configMap = (Map) GSON.fromJson(configJson, Object.class);
            if (configMap.isEmpty()) {
                exceptions.add("The Json for Task Config cannot be empty");
            }
            for (Map.Entry<String, Object> entry : configMap.entrySet()) {
                TaskConfigProperty property = new TaskConfigProperty(entry.getKey(), null);
                property.with(Property.REQUIRED, true);

                Map propertyValue = (Map) entry.getValue();
                if (propertyValue != null) {
                    if (propertyValue.containsKey("default-value")) {
                        if (!(propertyValue.get("default-value") instanceof String)) {
                            exceptions.add(String.format("Key: '%s' - The Json for Task Config should contain a not-null 'default-value' of type String", entry.getKey()));
                        } else {
                            property.withDefault((String) propertyValue.get("default-value"));
                        }
                    }
                    if (propertyValue.containsKey("display-name")) {
                        if (!(propertyValue.get("display-name") instanceof String)) {
                            exceptions.add(String.format("Key: '%s' - 'display-name' should be of type String", entry.getKey()));
                        } else {
                            property.with(Property.DISPLAY_NAME, (String) propertyValue.get("display-name"));
                        }
                    }
                    if (propertyValue.containsKey("display-order")) {
                        if (!(propertyValue.get("display-order") instanceof String && StringUtil.isInteger((String) propertyValue.get("display-order")))) {
                            exceptions.add(String.format("Key: '%s' - 'display-order' should be a String containing a numerical value", entry.getKey()));
                        } else {
                            property.with(Property.DISPLAY_ORDER, Integer.parseInt((String) propertyValue.get("display-order")));
                        }
                    }
                    if (propertyValue.containsKey("secure")) {
                        if (!(propertyValue.get("secure") instanceof Boolean)) {
                            exceptions.add(String.format("Key: '%s' - The Json for Task Config should contain a 'secure' field of type Boolean", entry.getKey()));
                        } else {
                            property.with(Property.SECURE, (Boolean) propertyValue.get("secure"));
                        }
                    }
                    if (propertyValue.containsKey("required")) {
                        if (!(propertyValue.get("required") instanceof Boolean)) {
                            exceptions.add(String.format("Key: '%s' - The Json for Task Config should contain a 'required' field of type Boolean", entry.getKey()));
                        } else {
                            property.with(Property.REQUIRED, (Boolean) propertyValue.get("required"));
                        }
                    }
                }
                taskConfig.add(property);
            }
            if (!exceptions.isEmpty()) {
                throw new RuntimeException(StringUtils.join(exceptions, ", "));
            }
            return taskConfig;
        } catch (Exception e) {
            LOGGER.error("Error occurred while converting the Json to Task Config. Error: {}. The Json received was '{}'.", e.getMessage(), configJson);
            throw new RuntimeException(String.format("Error occurred while converting the Json to Task Config. Error: %s.", e.getMessage()));
        }
    }
@Test
    public void shouldThrowExceptionForWrongJsonWhileConvertingJsonToTaskConfig() {
        String json1 = "{}";
        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig(json1);
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: The Json for Task Config cannot be empty."));
        }

        String json2 = "{\"URL\":{\"default-value\":true,\"secure\":false,\"required\":true}}";
        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig(json2);
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - The Json for Task Config should contain a not-null 'default-value' of type String."));
        }

        String json3 = "{\"URL\":{\"default-value\":\"some value\",\"secure\":\"string\",\"required\":true}}";
        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig(json3);
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - The Json for Task Config should contain a 'secure' field of type Boolean."));
        }

        String json4 = "{\"URL\":{\"default-value\":\"some value\",\"secure\":false,\"required\":\"string\"}}";
        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig(json4);
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - The Json for Task Config should contain a 'required' field of type Boolean."));
        }

        String json5 = "{\"URL1\":{\"default-value\":true,\"secure\":null,\"required\":true}," +
                "\"URL2\":{\"default-value\":\"some value\",\"secure\":\"some-string\",\"required\":false}," +
                "\"URL3\":{\"default-value\":\"some value\",\"secure\":true,\"required\":\"some-string\"}}";
        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig(json5);
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL1' - The Json for Task Config should contain a not-null 'default-value' of type String, Key: 'URL1' - The Json for Task Config should contain a 'secure' field of type Boolean, Key: 'URL2' - The Json for Task Config should contain a 'secure' field of type Boolean, Key: 'URL3' - The Json for Task Config should contain a 'required' field of type Boolean."));
        }

        assertThat(new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig("{\"URL\":{\"display-order\":\"1\"}}").get("URL").getOption(Property.DISPLAY_ORDER), is(1));

        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig("{\"URL\":{\"display-order\":\"first\"}}");
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - 'display-order' should be a String containing a numerical value."));
        }

        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig("{\"URL\":{\"display-order\":1}}");
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - 'display-order' should be a String containing a numerical value."));
        }

        assertThat(new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig("{\"URL\":{\"display-name\":\"Uniform Resource Locator\"}}").get("URL").getOption(Property.DISPLAY_NAME), is("Uniform Resource Locator"));

        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig("{\"URL\":{\"display-name\":{}}}");
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - 'display-name' should be of type String."));
        }

        try {
            new JsonBasedTaskExtensionHandler_V1().convertJsonToTaskConfig("{\"URL\":{\"display-name\":1}}");
            fail("should throw exception");
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Error occurred while converting the Json to Task Config. Error: Key: 'URL' - 'display-name' should be of type String."));
        }
    }